packages feed

positive-integer 0.1.2.1 → 0.1.3.0

raw patch · 3 files changed

+30/−6 lines, 3 filesdep ~basePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base

API changes (from Hackage documentation)

+ Numeric.PositiveInteger: prev :: PositiveInteger -> Maybe PositiveInteger
+ Numeric.PositiveInteger: quotRem :: PositiveInteger -> PositiveInteger -> (Natural, Natural)

Files

changelog.md view
@@ -1,3 +1,7 @@+## 0.1.3.0+* New functions: `prev` and `quotRem`.+* Write the `Show` instance in terms of `showsPrec` instead of `show`.+ ## 0.1.2.1 * Fixed haddock comments. * Support base-4.22.
lib/Numeric/PositiveInteger.hs view
@@ -36,10 +36,12 @@   , withTypeNat1     -- * Operations   , next+  , prev   , add   , sub   , mul   , div+  , quotRem     -- * Positive lengths   , length     -- * Non-empty lists@@ -48,7 +50,7 @@   , replicateM     ) where -import Prelude hiding (fromIntegral, div, length, take, replicate)+import Prelude hiding (fromIntegral, div, quotRem, length, take, replicate) import Prelude qualified import Numeric.Natural (Natural) import Text.Read (readPrec)@@ -77,7 +79,7 @@ one = PositiveInteger 1  instance Show PositiveInteger where-  show (PositiveInteger n) = show n+  showsPrec p (PositiveInteger n) = showsPrec p n  instance Read PositiveInteger where   readPrec = do@@ -133,7 +135,7 @@       case cmpNat proxy (Proxy @0) of         GTI -> f proxy         -- This case should be impossible.-        _ -> error "Positive integer is not positive!"+        _ -> error "withTypeNat: Positive integer is not positive!"  -- | Convert a type-level natural in @1 + n@ form to a positive integer. --@@ -155,6 +157,16 @@ {-# INLINE next #-} next (PositiveInteger n) = PositiveInteger (n+1) +-- | Return the previous positive integer.+--+-- @since 0.1.3.0+prev :: PositiveInteger -> Maybe PositiveInteger+{-# INLINE prev #-}+prev (PositiveInteger n) =+  case n of+    1 -> Nothing+    _ -> Just $ PositiveInteger (n-1)+ -- | Add two positive integers. add :: PositiveInteger -> PositiveInteger -> PositiveInteger {-# INLINE add #-}@@ -179,6 +191,13 @@ div (PositiveInteger n) (PositiveInteger m) =   if m <= n then Just (PositiveInteger (Prelude.div n m)) else Nothing +-- | Get quotient and remainder of dividing two positive integers.+--+-- @since 0.1.3.0+quotRem :: PositiveInteger -> PositiveInteger -> (Natural, Natural)+{-# INLINE quotRem #-}+quotRem (PositiveInteger n) (PositiveInteger m) = Prelude.quotRem n m+ {-  Starting on base-4.18.0.0, the type class Foldable1 becomes available.@@ -190,7 +209,7 @@ -- | Length of a non-empty data structure. length :: Foldable1 t => t a -> PositiveInteger #else--- | Lenght of a non-empty list.+-- | Length of a non-empty list. length :: NonEmpty a -> PositiveInteger #endif {-# INLINE length #-}@@ -198,6 +217,7 @@  -- | Take a positive number of elements from a non-empty list. take :: PositiveInteger -> NonEmpty a -> NonEmpty a+{-# INLINE take #-} take (PositiveInteger n) (x NonEmpty.:| xs) =   x NonEmpty.:| Prelude.take (Prelude.fromIntegral $ n - 1) xs 
positive-integer.cabal view
@@ -1,5 +1,5 @@ name: positive-integer-version: 0.1.2.1+version: 0.1.3.0 category: Numeric synopsis: Type of positive integers. description: Type of positive integers together with related functions.@@ -18,4 +18,4 @@   exposed-modules: Numeric.PositiveInteger   ghc-options: -Wall   default-extensions: ImportQualifiedPost-  build-depends: base >= 4.16.0.0 && < 4.23.0.0+  build-depends: base >= 4.16.0.0 && < 4.23