module Generics.Instant.Functions.Hashable
(
ghashWithSaltDefault
, RepGHashable
, GHashable(..)
) where
import Data.Hashable (Hashable(hashWithSalt))
import Generics.Instant
ghashWithSaltDefault :: (Representable a, GHashable (Rep a)) => Int -> a -> Int
ghashWithSaltDefault = \s a -> ghashWithSalt s (from a)
class (Representable a, GHashable (Rep a)) => RepGHashable a
instance (Representable a, GHashable (Rep a)) => RepGHashable a
class GHashable a where
ghashWithSalt :: Int -> a -> Int
instance GHashable Z where
ghashWithSalt _ _ = error
"Generics.Instant.Functions.Hashable.GHashable Z ghashWithSalt - impossible"
instance GHashable U where
ghashWithSalt s U = hashWithSalt s ()
instance GHashable a => GHashable (CEq c p q a) where
ghashWithSalt s (C a) = ghashWithSalt s a
instance (GHashable a, GHashable b) => GHashable (a :*: b) where
ghashWithSalt s (a :*: b) = ghashWithSalt (ghashWithSalt s a) b
instance (GHashable a, GHashable b) => GHashable (a :+: b) where
ghashWithSalt s lr = 0 `hashWithSalt` case lr of
L a -> Left (ghashWithSalt s a)
R b -> Right (ghashWithSalt s b)
instance Hashable a => GHashable (Var a) where
ghashWithSalt s (Var a) = hashWithSalt s a
instance Hashable a => GHashable (Rec a) where
ghashWithSalt s (Rec a) = hashWithSalt s a