packages feed

hashable-generics 1.1.3 → 1.1.4

raw patch · 3 files changed

+27/−8 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Data/Hashable/Generic.hs view
@@ -9,6 +9,7 @@                              ) where  import Data.Hashable+import Data.Word import GHC.Generics  -- | "GHC.Generics"-based 'hashWithSalt' implementation@@ -58,6 +59,15 @@ gHashWithSalt salt x = gHashWithSalt_ salt $ from x {-# INLINE gHashWithSalt #-} +-- | A value with bit pattern (01)* (or 5* in hexa), for any size of Int.+--   It is used as data constructor distinguisher. GHC computes its value during+--   compilation.+--+--   Blatantly stolen from @hashable@.+distinguisher :: Int+distinguisher = fromIntegral $ (maxBound :: Word) `quot` 3+{-# INLINE distinguisher #-}+ -- | Hidden internal type class. class GHashable f where     gHashWithSalt_ :: Int -> f a -> Int@@ -81,6 +91,6 @@ -- This instance is suboptimal (with the salt+1 hackery). Is there a better way -- to be doing this so that both choices can be unique? instance (GHashable a, GHashable b) => GHashable (a :+: b) where-    gHashWithSalt_ !salt (L1 x) = gHashWithSalt_ salt     x-    gHashWithSalt_ !salt (R1 x) = gHashWithSalt_ (salt+1) x+    gHashWithSalt_ !salt (L1 x) = gHashWithSalt_ (salt `combine` 0) x+    gHashWithSalt_ !salt (R1 x) = gHashWithSalt_ (salt `combine` distinguisher) x     {-# INLINE gHashWithSalt_ #-}
hashable-generics.cabal view
@@ -1,5 +1,5 @@ name:                hashable-generics-version:             1.1.3+version:             1.1.4 synopsis:            Automatically generates Hashable instances with GHC.Generics. description:     This package provides a "GHC.Generics"-based 'Data.Hashable.Generic.gHashWithSalt'
test/Suite.hs view
@@ -7,7 +7,9 @@ import Test.Framework.Providers.QuickCheck2 import Test.QuickCheck +import Data.Hashable import Data.Hashable.Generic+import Data.Word  import GHC.Generics @@ -22,6 +24,13 @@             ]         ] +-- | A value with bit pattern (01)* (or 5* in hexa), for any size of Int.+--   It is used as data constructor distinguisher. GHC computes its value during+--   compilation.+distinguisher :: Int+distinguisher = fromIntegral $ (maxBound :: Word) `quot` 3+{-# INLINE distinguisher #-}+ data FooA = FooA AccountId Name Address     deriving (Generic, Show) @@ -67,8 +76,8 @@     hashWithSalt = gHashWithSalt  instance Hashable NB where-    hashWithSalt !salt ZB      = hashWithSalt salt ()-    hashWithSalt !salt (SB xs) = hashWithSalt (salt+1) xs+    hashWithSalt !salt ZB      = hashWithSalt (salt `combine` 0) ()+    hashWithSalt !salt (SB xs) = hashWithSalt (salt `combine` distinguisher) xs  instance Arbitrary NA where     arbitrary = lst2A <$> arbitrary@@ -100,9 +109,9 @@     hashWithSalt = gHashWithSalt  instance Hashable a => Hashable (BarB a) where-    hashWithSalt !salt BarB0 = hashWithSalt salt ()-    hashWithSalt !salt (BarB1 x) = hashWithSalt (salt+1) x-    hashWithSalt !salt (BarB2 x) = hashWithSalt (salt+2) x+    hashWithSalt !salt BarB0 = hashWithSalt (salt `combine` 0) ()+    hashWithSalt !salt (BarB1 x) = hashWithSalt (salt `combine` distinguisher `combine` 0) x+    hashWithSalt !salt (BarB2 x) = hashWithSalt (salt `combine` distinguisher `combine` distinguisher) x  barA2B :: BarA a -> BarB a barA2B BarA0 = BarB0