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

Moduleequivalence-0.4.1Haskell2010

Data.Equivalence.Monad

This is an alternative interface to the union-find implementation in 'Data.Equivalence.STT'. It is wrapped into the monad transformer EquivT.

  • 4 types
  • 1 class
  • 4 values
classclass (Monad m, Applicative m, Ord v) => MonadEquiv c v d (m :: Type -> Type) | m -> v, m -> c, m -> d where
#

This class specifies the interface for a monadic computation that maintains an equivalence relation.

Methods

  • equivalent :: v -> v -> m Bool

    This function decides whether the two given elements are equivalent in the current equivalence relation.

  • classDesc :: v -> m d

    This function obtains the descriptor of the given element's equivalence class.

  • equateAll :: [v] -> m ()

    This function equates the element in the given list. That is, it unions the equivalence classes of the elements and combines their descriptor.

  • equate :: v -> v -> m ()

    This function equates the given two elements. That is it unions the equivalence classes of the two elements.

  • removeClass :: v -> m Bool

    This function removes the equivalence class of the given element. If there is no corresponding equivalence class, False is returned; otherwise True.

  • getClass :: v -> m c

    This function provides the equivalence class of the given element.

  • combineAll :: [c] -> m ()

    This function combines all equivalence classes in the given list. Afterwards all elements in the argument list represent the same equivalence class!

  • combine :: c -> c -> m c

    This function combines the two given equivalence classes. Afterwards both arguments represent the same equivalence class! One of it is returned in order to represent the new combined equivalence class.

  • (===) :: c -> c -> m Bool

    This function decides whether the two given equivalence classes are the same.

  • desc :: c -> m d

    This function returns the descriptor of the given equivalence class.

  • remove :: c -> m Bool

    This function removes the given equivalence class. If the equivalence class does not exist anymore, False is returned; otherwise True.

  • values :: m [v]

    This function returns all values represented by some equivalence class.

  • classes :: m [c]

    This function returns the list of all equivalence classes.

Instances5MonadEquiv
newtypenewtype EquivT s c v (m :: Type -> Type) a
#

This monad transformer encapsulates computations maintaining an equivalence relation. A monadic computation of type EquivT s c v m a maintains a state space indexed by type s, maintains an equivalence relation over elements of type v with equivalence class descriptors of type c and contains an internal monadic computation of type m a.

Constructors

Instances10MonadError, MonadReader, MonadState, MonadWriter, MonadTrans, MonadEquiv, …
typetype EquivT' s = EquivT s ()
#

This monad transformer is a special case of EquivT that only maintains trivial equivalence class descriptors of type ().

typetype EquivM s c v = EquivT s c v Identity
#

This monad encapsulates computations maintaining an equivalence relation. A monadic computation of type EquivM s c v a maintains a state space indexed by type s, maintains an equivalence relation over elements of type v with equivalence class descriptors of type c and returns a value of type a.

typetype EquivM' s v = EquivM s () v
#

This monad is a special case of EquivM that only maintains trivial equivalence class descriptors of type ().

valuerunEquivT
  1. :: (Monad m, Applicative m)
  2. => (v -> c)

    Used to construct an equivalence class descriptor for a singleton class.

  3. -> (c -> c -> c)

    Used to combine the equivalence class descriptor of two classes which are meant to be combined.

  4. -> (forall s. EquivT s c v m a)
  5. -> m a
#

This function runs a monadic computation that maintains an equivalence relation. The first two arguments specify how to construct an equivalence class descriptor for a singleton class and how to combine two equivalence class descriptors.

valuerunEquivM
  1. :: (v -> c)

    Used to construct an equivalence class descriptor for a singleton class.

  2. -> (c -> c -> c)

    Used to combine the equivalence class descriptor of two classes which are meant to be combined.

  3. -> (forall s. EquivM s c v a)
  4. -> a
#

This function runs a monadic computation that maintains an equivalence relation. The first tow arguments specify how to construct an equivalence class descriptor for a singleton class and how to combine two equivalence class descriptors.

valuerunEquivM' :: (forall s. EquivM' s v a) -> a
#

This function is a special case of runEquivM that only maintains trivial equivalence class descriptors of type ().