integer-types 0.0.0.1 → 0.1.0.0
raw patch · 5 files changed
+38/−7 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Integer.Natural: length :: [a] -> Natural
+ Integer.Positive: length :: NonEmpty a -> Positive
- Integer.Natural: addOne :: Integer -> Integer
+ Integer.Natural: addOne :: Natural -> Positive
Files
- changelog.md +14/−2
- integer-types.cabal +1/−1
- library/Integer/Natural.hs +10/−4
- library/Integer/Positive.hs +6/−0
- test/Main.hs +7/−0
changelog.md view
@@ -1,9 +1,21 @@-# 0.0.0.1+## 0.1.0.0 (2023-02-09) +Change type of `Integer.Natural.addOne` from+`Integer -> Integer` to `Natural -> Positive`++New functions:++```haskell+Integer.Natural.length :: [a] -> Natural+Integer.Positive.length :: NonEmpty a -> Positive+```++## 0.0.0.1 (2023-01-16)+ Consolidate all the test suites into one Remove `Safe` pragmas -# 0.0.0.0 (2022-11-29)+## 0.0.0.0 (2022-11-29) Initial release
integer-types.cabal view
@@ -1,7 +1,7 @@ cabal-version: 3.0 name: integer-types-version: 0.0.0.1+version: 0.1.0.0 category: Numeric synopsis: Integer, Natural, and Positive
library/Integer/Natural.hs view
@@ -9,6 +9,7 @@ {- ** Int -} toInt, fromInt, {- ** Word -} toWord, fromWord, {- * One (1) -} one, addOne, subtractOne,+ {- * List -} length, ) where @@ -18,8 +19,10 @@ import Data.Word (Word) import Integer.Signed (Signed (..)) import Numeric.Natural (Natural)+import Integer.Positive.Unsafe (Positive) import Prelude (Integer) +import qualified Data.List as List import qualified Data.Ord as Ord import qualified Integer.Positive as Positive import qualified Integer.Positive.Unsafe as Positive.Unsafe@@ -27,10 +30,10 @@ import qualified Prelude as Bounded (Bounded (..)) import qualified Prelude as Num (Integral (..), Num (..)) -toPositive :: Natural -> Maybe Positive.Unsafe.Positive+toPositive :: Natural -> Maybe Positive toPositive = Positive.fromNatural -fromPositive :: Positive.Unsafe.Positive -> Natural+fromPositive :: Positive -> Natural fromPositive = Positive.toNatural fromInteger :: Integer -> Maybe Natural@@ -75,10 +78,13 @@ one :: Natural one = 1 -addOne :: Integer -> Integer-addOne = (Num.+ 1)+addOne :: Natural -> Positive+addOne x = Positive.Unsafe.fromNatural (x Num.+ 1) subtractOne :: Natural -> Maybe Signed subtractOne x = case x of 0 -> Nothing p -> Just (subtract p 1)++length :: [a] -> Natural+length = List.foldl' (\x _ -> x Num.+ 1) 0
library/Integer/Positive.hs view
@@ -9,18 +9,21 @@ {- ** Int -} toInt, fromInt, {- ** Word -} toWord, fromWord, {- * One (1) -} one, addOne, subtractOne,+ {- * List -} length, ) where import Essentials import Data.Int (Int)+import Data.List.NonEmpty (NonEmpty (..)) import Data.Word (Word) import Integer.Positive.Unsafe (Positive, addOne, one, toInteger, toNatural) import Integer.Signed (Signed (..)) import Numeric.Natural (Natural) import Prelude (Integer) +import qualified Data.List as List import qualified Data.Ord as Ord import qualified Integer.Positive.Unsafe as Unsafe import qualified Prelude as Bounded (Bounded (..))@@ -71,3 +74,6 @@ fromSigned :: Signed -> Maybe Positive fromSigned (Plus x) = Just x fromSigned _ = Nothing++length :: NonEmpty a -> Positive+length (_ :| xs) = List.foldl' (\x _ -> x Num.+ 1) 1 xs
test/Main.hs view
@@ -13,6 +13,7 @@ import Data.Either (Either (..)) import Data.Int (Int) import Data.List (take)+import Data.List.NonEmpty (NonEmpty ((:|))) import Data.Word (Word) import Integer.Gen (GenFinite) import Integer.Gen (GenIntegral)@@ -26,6 +27,8 @@ import qualified Data.Ord as Ord import qualified Hedgehog import qualified Integer.Gen as Gen+import qualified Integer.Natural as Natural+import qualified Integer.Positive as Positive import qualified Prelude as Bounded (Bounded (..)) import qualified Prelude as Num (fromInteger) import qualified Prelude as Num (toInteger)@@ -267,6 +270,10 @@ it "can force an error in magnitude" $ do x <- force (NonZero MinusSign (throw X)) x `shouldBe` Left X++ describe "length" $ do+ it "Natural" $ Natural.length "abc" `shouldBe` 3+ it "Positive" $ Positive.length ('a' :| "bc") `shouldBe` 3 data X = X deriving (Eq, Show)