integer-types 0.1.0.0 → 0.1.1.0
raw patch · 6 files changed
+27/−8 lines, 6 filesdep +hashabledep ~basedep ~hspecPVP ok
version bump matches the API change (PVP)
Dependencies added: hashable
Dependency ranges changed: base, hspec
API changes (from Hackage documentation)
+ Integer.Sign: instance Data.Hashable.Class.Hashable Integer.Sign.Sign
+ Integer.Sign: instance GHC.Enum.Bounded Integer.Sign.Sign
+ Integer.Sign: instance GHC.Enum.Enum Integer.Sign.Sign
+ Integer.Signed: instance Data.Hashable.Class.Hashable Integer.Signed.Signed
Files
- changelog.md +6/−0
- integer-types.cabal +4/−4
- library/Integer/Positive/Unsafe.hs +3/−1
- library/Integer/Sign.hs +6/−1
- library/Integer/Signed.hs +7/−1
- test/Main.hs +1/−1
changelog.md view
@@ -1,3 +1,9 @@+## 0.1.1.0 (2023-04-22)++Add `Hashable` instances for `Positive`, `Sign`, and `Signed`++Add `Enum` and `Bounded` instances for `Sign`+ ## 0.1.0.0 (2023-02-09) Change type of `Integer.Natural.addOne` from
integer-types.cabal view
@@ -1,7 +1,7 @@ cabal-version: 3.0 name: integer-types-version: 0.1.0.0+version: 0.1.1.0 category: Numeric synopsis: Integer, Natural, and Positive@@ -26,14 +26,14 @@ default-language: GHC2021 ghc-options: -Wall default-extensions:- MultiParamTypeClasses- NoGeneralizedNewtypeDeriving+ DerivingStrategies NoImplicitPrelude PatternSynonyms ViewPatterns build-depends:- , base ^>= 4.16 || ^>= 4.17+ , base ^>= 4.16 || ^>= 4.17 || ^>= 4.18 , deepseq ^>= 1.4.6+ , hashable ^>= 1.4.1 , quaalude ^>= 0.0 library
library/Integer/Positive/Unsafe.hs view
@@ -18,6 +18,7 @@ import Essentials ( ($), Enum, Eq, Ord, Show, (.), id ) +import Data.Hashable (Hashable) import Integer.BoundedBelow (BoundedBelow) import Numeric.Natural (Natural) import Prelude (Int, Integer, Integral, Num, Real)@@ -34,7 +35,8 @@ fromIntegral) import qualified Text.Show as Show -newtype Positive = FromNatural{ toNatural :: Natural } deriving (Eq, Ord)+newtype Positive = FromNatural{ toNatural :: Natural }+ deriving newtype (Eq, Ord, Hashable) instance DeepSeq.NFData Positive where rnf (FromNatural x) = DeepSeq.rnf x
library/Integer/Sign.hs view
@@ -8,13 +8,18 @@ import Essentials import Prelude (seq)+import qualified Prelude as Enum (Enum (..))+import Data.Hashable (Hashable (hashWithSalt)) import qualified Control.DeepSeq as DeepSeq data Sign = MinusSign | PlusSign- deriving (Eq, Ord, Show)+ deriving stock (Eq, Ord, Show, Enum, Bounded) instance DeepSeq.NFData Sign where rnf x = seq x ()++instance Hashable Sign where+ hashWithSalt salt x = salt `hashWithSalt` (Enum.fromEnum x) negate :: Sign -> Sign negate PlusSign = MinusSign
library/Integer/Signed.hs view
@@ -12,6 +12,7 @@ import Essentials +import Data.Hashable (Hashable (hashWithSalt)) import Data.Int (Int) import Data.Word (Word) import Integer.Positive.Unsafe (Positive)@@ -30,7 +31,7 @@ import qualified Text.Show as Show data Signed = Zero | NonZero Sign Positive- deriving (Eq)+ deriving stock (Eq) instance Ord Signed where compare Zero Zero = Ord.EQ@@ -48,6 +49,11 @@ instance DeepSeq.NFData Signed where rnf Zero = () rnf (NonZero a b) = a `seq` b `seq` ()++instance Hashable Signed where+ hashWithSalt s Zero = s `hashWithSalt` ( 0 :: Int)+ hashWithSalt s (Plus x) = s `hashWithSalt` ( 1 :: Int) `hashWithSalt` x+ hashWithSalt s (Minus x) = s `hashWithSalt` (-1 :: Int) `hashWithSalt` x pattern Minus :: Positive -> Signed pattern Minus x = NonZero MinusSign x
test/Main.hs view
@@ -276,7 +276,7 @@ it "Positive" $ Positive.length ('a' :| "bc") `shouldBe` 3 data X = X- deriving (Eq, Show)+ deriving stock (Eq, Show) instance Exception X