hashable-1.4.7.0: A class for types that can be converted to a hash value
Copyright(c) Milan Straka 2010
(c) Johan Tibell 2011
(c) Bryan O'Sullivan 2011 2012
LicenseBSD-3-Clause
Maintainerjohan.tibell@gmail.com
Stabilityprovisional
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Data.Hashable.Lifted

Description

Lifting of the Hashable class to unary and binary type constructors. These classes are needed to express the constraints on arguments of types that are parameterized by type constructors. Fixed-point data types and monad transformers are such types.

Synopsis

Type Classes

class Eq1 t => Hashable1 t where Source #

Minimal complete definition

Nothing

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> t a -> Int Source #

Lift a hashing function through the type constructor.

default liftHashWithSalt :: (Generic1 t, GHashable One (Rep1 t)) => (Int -> a -> Int) -> Int -> t a -> Int Source #

Instances

Instances details
Hashable1 Complex Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> Complex a -> Int Source #

Hashable1 Identity Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> Identity a -> Int Source #

Hashable1 NonEmpty Source #

Since: 1.3.1.0

Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> NonEmpty a -> Int Source #

Hashable1 IntMap Source #

Since: 1.3.4.0

Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> IntMap a -> Int Source #

Hashable1 Seq Source #

Since: 1.3.4.0

Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> Seq a -> Int Source #

Hashable1 Set Source #

Since: 1.3.4.0

Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> Set a -> Int Source #

Hashable1 Tree Source #

Since: 1.3.4.0

Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> Tree a -> Int Source #

Hashable1 Hashed Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> Hashed a -> Int Source #

Hashable1 Maybe Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> Maybe a -> Int Source #

Hashable1 Solo Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> Solo a -> Int Source #

Hashable1 List Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> [a] -> Int Source #

Hashable a => Hashable1 (Either a) Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a0 -> Int) -> Int -> Either a a0 -> Int Source #

Hashable1 (Proxy :: Type -> Type) Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> Proxy a -> Int Source #

Hashable k => Hashable1 (Map k) Source #

Since: 1.3.4.0

Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> Map k a -> Int Source #

Hashable a1 => Hashable1 ((,) a1) Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> (a1, a) -> Int Source #

Hashable a => Hashable1 (Const a :: Type -> Type) Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a0 -> Int) -> Int -> Const a a0 -> Int Source #

(Hashable a1, Hashable a2) => Hashable1 ((,,) a1 a2) Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> (a1, a2, a) -> Int Source #

(Hashable1 f, Hashable1 g) => Hashable1 (Product f g) Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> Product f g a -> Int Source #

(Hashable1 f, Hashable1 g) => Hashable1 (Sum f g) Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> Sum f g a -> Int Source #

(Hashable a1, Hashable a2, Hashable a3) => Hashable1 ((,,,) a1 a2 a3) Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> (a1, a2, a3, a) -> Int Source #

(Hashable1 f, Hashable1 g) => Hashable1 (Compose f g) Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> Compose f g a -> Int Source #

class Eq2 t => Hashable2 t where Source #

Methods

liftHashWithSalt2 :: (Int -> a -> Int) -> (Int -> b -> Int) -> Int -> t a b -> Int Source #

Lift a hashing function through the binary type constructor.

Instances

Instances details
Hashable2 Either Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt2 :: (Int -> a -> Int) -> (Int -> b -> Int) -> Int -> Either a b -> Int Source #

Hashable2 Map Source #

Since: 1.3.4.0

Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt2 :: (Int -> a -> Int) -> (Int -> b -> Int) -> Int -> Map a b -> Int Source #

Hashable2 (,) Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt2 :: (Int -> a -> Int) -> (Int -> b -> Int) -> Int -> (a, b) -> Int Source #

Hashable2 (Const :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt2 :: (Int -> a -> Int) -> (Int -> b -> Int) -> Int -> Const a b -> Int Source #

Hashable a1 => Hashable2 ((,,) a1) Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt2 :: (Int -> a -> Int) -> (Int -> b -> Int) -> Int -> (a1, a, b) -> Int Source #

(Hashable a1, Hashable a2) => Hashable2 ((,,,) a1 a2) Source # 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt2 :: (Int -> a -> Int) -> (Int -> b -> Int) -> Int -> (a1, a2, a, b) -> Int Source #

Auxiliary Functions

hashWithSalt1 :: (Hashable1 f, Hashable a) => Int -> f a -> Int Source #

Lift the hashWithSalt function through the type constructor.

hashWithSalt1 = liftHashWithSalt hashWithSalt

hashWithSalt2 :: (Hashable2 f, Hashable a, Hashable b) => Int -> f a b -> Int Source #

Lift the hashWithSalt function through the type constructor.

hashWithSalt2 = liftHashWithSalt2 hashWithSalt hashWithSalt

defaultLiftHashWithSalt :: (Hashable2 f, Hashable a) => (Int -> b -> Int) -> Int -> f a b -> Int Source #

Lift the hashWithSalt function halfway through the type constructor. This function makes a suitable default implementation of liftHashWithSalt, given that the type constructor t in question can unify with f a.

Motivation

This type classes provided in this module are used to express constraints on type constructors in a Haskell98-compatible fashion. As an example, consider the following two types (Note that these instances are not actually provided because hashable does not have transformers or free as a dependency):

newtype WriterT w m a = WriterT { runWriterT :: m (a, w) }
data Free f a = Pure a | Free (f (Free f a))

The Hashable1 instances for WriterT and Free could be written as:

instance (Hashable w, Hashable1 m) => Hashable1 (WriterT w m) where
    liftHashWithSalt h s (WriterT m) =
        liftHashWithSalt (liftHashWithSalt2 h hashWithSalt) s m
instance Hashable1 f => Hashable1 (Free f) where
    liftHashWithSalt h = go where
        go s x = case x of
            Pure a -> h s a
            Free p -> liftHashWithSalt go s p

The Hashable instances for these types can be trivially recovered with hashWithSalt1:

instance (Hashable w, Hashable1 m, Hashable a) => Hashable (WriterT w m a) where
    hashWithSalt = hashWithSalt1
instance (Hashable1 f, Hashable a) => Hashable (Free f a) where
    hashWithSalt = hashWithSalt1