HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulehashable-1.4.7.0Haskell2010

Data.Hashable.Lifted

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.

  • 2 classes
  • 3 values
  • Packagehashable-1.4.7.0
  • Exports5
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceLifted.hs

Type Classes

2 declarations
classclass Eq1 t => Hashable1 (t :: Type -> Type) where
#

Methods

Instances21Hashable1, …
classclass Eq2 t => Hashable2 (t :: Type -> Type -> Type) where
#

Methods

Instances6Hashable2

Auxiliary Functions

3 declarations

Motivation

0 declarations

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