File tree 2 files changed +26
-3
lines changed 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -43,18 +43,18 @@ import Data.Hashable.Class
43
43
-- > instance (Hashable w, Hashable1 m) => Hashable1 (WriterT w m) where
44
44
-- > liftHashWithSalt h s (WriterT m) =
45
45
-- > liftHashWithSalt (liftHashWithSalt2 h hashWithSalt) s m
46
- -- > instance ( Hashable1 f, Functor f) => Hashable1 (Free f) where
46
+ -- > instance Hashable1 f => Hashable1 (Free f) where
47
47
-- > liftHashWithSalt h = go where
48
48
-- > go s x = case x of
49
49
-- > Pure a -> h s a
50
- -- > Free p -> liftHashWithSalt go p
50
+ -- > Free p -> liftHashWithSalt go s p
51
51
--
52
52
-- The 'Hashable' instances for these types can be trivially recovered with
53
53
-- 'hashWithSalt1':
54
54
--
55
55
-- > instance (Hashable w, Hashable1 m, Hashable a) => Hashable (WriterT w m a) where
56
56
-- > hashWithSalt = hashWithSalt1
57
- -- > instance (Hashable1 f, Hashable a) => Hashable1 (Free f a) where
57
+ -- > instance (Hashable1 f, Hashable a) => Hashable (Free f a) where
58
58
-- > hashWithSalt = hashWithSalt1
59
59
60
60
--
Original file line number Diff line number Diff line change 1
1
{-# LANGUAGE DeriveGeneric #-}
2
2
import Data.Hashable
3
+ import Data.Hashable.Lifted
3
4
import GHC.Generics (Generic )
4
5
5
6
data Foo
@@ -25,3 +26,25 @@ main = do
25
26
print . hash $ Foo2 " hello" ()
26
27
putStrLn " Hashing Bar"
27
28
print . hash $ Bar 55.50 9.125
29
+
30
+ -----------------------------------
31
+ -- Higher Rank Hashable Examples --
32
+ -----------------------------------
33
+
34
+ newtype WriterT w m a = WriterT { runWriterT :: m (a , w ) }
35
+ data Free f a = Pure a | Free (f (Free f a ))
36
+
37
+ instance (Hashable w , Hashable1 m ) => Hashable1 (WriterT w m ) where
38
+ liftHashWithSalt h s (WriterT m) =
39
+ liftHashWithSalt (liftHashWithSalt2 h hashWithSalt) s m
40
+ instance Hashable1 f => Hashable1 (Free f ) where
41
+ liftHashWithSalt h = go where
42
+ go s x = case x of
43
+ Pure a -> h s a
44
+ Free p -> liftHashWithSalt go s p
45
+
46
+ instance (Hashable w , Hashable1 m , Hashable a ) => Hashable (WriterT w m a ) where
47
+ hashWithSalt = hashWithSalt1
48
+ instance (Hashable1 f , Hashable a ) => Hashable (Free f a ) where
49
+ hashWithSalt = hashWithSalt1
50
+
You can’t perform that action at this time.
0 commit comments