compdata-0.13.1: Compositional Data Types
Copyright(c) 2011 Patrick Bahr
LicenseBSD3
MaintainerPatrick Bahr <paba@diku.dk>
Stabilityexperimental
Portabilitynon-portable (GHC Extensions)
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Comp.Multi.Algebra

Description

This module defines the notion of algebras and catamorphisms, and their generalizations to e.g. monadic versions and other (co)recursion schemes. All definitions are generalised versions of those in Data.Comp.Algebra.

Synopsis

Algebras & Catamorphisms

type Alg f e = f e :-> e Source #

This type represents multisorted f-algebras with a family e of carriers.

free :: forall f h a b. HFunctor f => Alg f b -> (a :-> b) -> Cxt h f a :-> b Source #

Construct a catamorphism for contexts over f with holes of type b, from the given algebra.

cata :: forall f a. HFunctor f => Alg f a -> Term f :-> a Source #

Construct a catamorphism from the given algebra.

cata' :: HFunctor f => Alg f e -> Cxt h f e :-> e Source #

A generalisation of cata from terms over f to contexts over f, where the holes have the type of the algebra carrier.

appCxt :: HFunctor f => Context f (Cxt h f a) :-> Cxt h f a Source #

This function applies a whole context into another context.

Monadic Algebras & Catamorphisms

type AlgM m f e = NatM m (f e) e Source #

This type represents a monadic algebra. It is similar to Alg but the return type is monadic.

freeM :: forall f m h a b. (HTraversable f, Monad m) => AlgM m f b -> NatM m a b -> NatM m (Cxt h f a) b Source #

Construct a monadic catamorphism for contexts over f with holes of type b, from the given monadic algebra.

cataM :: forall f m a. (HTraversable f, Monad m) => AlgM m f a -> NatM m (Term f) a Source #

This is a monadic version of cata.

cataM' :: forall m h a f. (Monad m, HTraversable f) => AlgM m f a -> NatM m (Cxt h f a) a Source #

liftMAlg :: forall m f. (Monad m, HTraversable f) => Alg f I -> Alg f m Source #

This function lifts a many-sorted algebra to a monadic domain.

Term Homomorphisms

type CxtFun f g = forall h. SigFun (Cxt h f) (Cxt h g) Source #

This type represents context function.

type SigFun f g = forall (a :: Type -> Type). f a :-> g a Source #

This type represents uniform signature function specification.

type Hom f g = SigFun f (Context g) Source #

This type represents term homomorphisms.

appHom :: forall f g. (HFunctor f, HFunctor g) => Hom f g -> CxtFun f g Source #

This function applies the given term homomorphism to a term/context.

appHom' :: forall f g. HFunctor g => Hom f g -> CxtFun f g Source #

This function applies the given term homomorphism to a term/context. This is the top-down variant of appHom.

compHom :: (HFunctor g, HFunctor h) => Hom g h -> Hom f g -> Hom f h Source #

This function composes two term algebras.

appSigFun :: forall f g. HFunctor f => SigFun f g -> CxtFun f g Source #

This function applies a signature function to the given context.

appSigFun' :: forall f g. HFunctor g => SigFun f g -> CxtFun f g Source #

This function applies a signature function to the given context. This is the top-down variant of appSigFun.

compSigFun :: SigFun g h -> SigFun f g -> SigFun f h Source #

This function composes two signature functions.

hom :: HFunctor g => SigFun f g -> Hom f g Source #

Lifts the given signature function to the canonical term homomorphism.

compAlg :: HFunctor g => Alg g a -> Hom f g -> Alg f a Source #

This function composes a term algebra with an algebra.

Monadic Term Homomorphisms

type CxtFunM m f g = forall h. SigFunM m (Cxt h f) (Cxt h g) Source #

This type represents monadic context function.

type SigFunM m f g = forall (a :: Type -> Type). NatM m (f a) (g a) Source #

This type represents monadic signature functions.

type HomM m f g = SigFunM m f (Context g) Source #

This type represents monadic term algebras.

sigFunM :: Monad m => SigFun f g -> SigFunM m f g Source #

This function lifts the given signature function to a monadic signature function. Note that term algebras are instances of signature functions. Hence this function also applies to term algebras.

hom' :: (HFunctor f, HFunctor g, Monad m) => SigFunM m f g -> HomM m f g Source #

This function lifts the give monadic signature function to a monadic term algebra.

appHomM :: forall f g m. (HTraversable f, HFunctor g, Monad m) => HomM m f g -> CxtFunM m f g Source #

This function applies the given monadic term homomorphism to the given term/context.

appHomM' :: forall f g m. (HTraversable g, Monad m) => HomM m f g -> CxtFunM m f g Source #

This function applies the given monadic term homomorphism to the given term/context. This is a top-down variant of appHomM.

homM :: (HFunctor g, Monad m) => SigFun f g -> HomM m f g Source #

This function lifts the given signature function to a monadic term algebra.

appSigFunM :: forall f g m. (HTraversable f, Monad m) => SigFunM m f g -> CxtFunM m f g Source #

This function applies the given monadic signature function to the given context.

appSigFunM' :: forall f g m. (HTraversable g, Monad m) => SigFunM m f g -> CxtFunM m f g Source #

This function applies the given monadic signature function to the given context. This is a top-down variant of appSigFunM.

compHomM :: (HTraversable g, HFunctor h, Monad m) => HomM m g h -> HomM m f g -> HomM m f h Source #

This function composes two monadic term algebras.

compSigFunM :: Monad m => SigFunM m g h -> SigFunM m f g -> SigFunM m f h Source #

This function composes two monadic signature functions.

compAlgM :: (HTraversable g, Monad m) => AlgM m g a -> HomM m f g -> AlgM m f a Source #

This function composes a monadic term algebra with a monadic algebra

compAlgM' :: (HTraversable g, Monad m) => AlgM m g a -> Hom f g -> AlgM m f a Source #

This function composes a monadic term algebra with a monadic algebra.

Coalgebras & Anamorphisms

type Coalg f a = a :-> f a Source #

ana :: forall f a. HFunctor f => Coalg f a -> a :-> Term f Source #

This function unfolds the given value to a term using the given unravelling function. This is the unique homomorphism a -> Term f from the given coalgebra of type a -> f a to the final coalgebra Term f.

type CoalgM m f a = NatM m a (f a) Source #

anaM :: forall a m f. (HTraversable f, Monad m) => CoalgM m f a -> NatM m a (Term f) Source #

This function unfolds the given value to a term using the given monadic unravelling function. This is the unique homomorphism a -> Term f from the given coalgebra of type a -> f a to the final coalgebra Term f.

R-Algebras & Paramorphisms

type RAlg f a = f (Term f :*: a) :-> a Source #

This type represents r-algebras over functor f and with domain a.

para :: forall f a. HFunctor f => RAlg f a -> Term f :-> a Source #

This function constructs a paramorphism from the given r-algebra

type RAlgM m f a = NatM m (f (Term f :*: a)) a Source #

This type represents monadic r-algebras over monad m and functor f and with domain a.

paraM :: forall f m a. (HTraversable f, Monad m) => RAlgM m f a -> NatM m (Term f) a Source #

This function constructs a monadic paramorphism from the given monadic r-algebra

R-Coalgebras & Apomorphisms

type RCoalg f a = a :-> f (Term f :+: a) Source #

This type represents r-coalgebras over functor f and with domain a.

apo :: forall f a. HFunctor f => RCoalg f a -> a :-> Term f Source #

This function constructs an apomorphism from the given r-coalgebra.

type RCoalgM m f a = NatM m a (f (Term f :+: a)) Source #

This type represents monadic r-coalgebras over monad m and functor f with domain a.

apoM :: forall f m a. (HTraversable f, Monad m) => RCoalgM m f a -> NatM m a (Term f) Source #

This function constructs a monadic apomorphism from the given monadic r-coalgebra.

CV-Coalgebras & Futumorphisms

type CVCoalg f a = a :-> f (Context f a) Source #

This type represents cv-coalgebras over functor f and with domain a.

futu :: forall f a. HFunctor f => CVCoalg f a -> a :-> Term f Source #

This function constructs the unique futumorphism from the given cv-coalgebra to the term algebra.

type CVCoalgM m f a = NatM m a (f (Context f a)) Source #

This type represents monadic cv-coalgebras over monad m and functor f, and with domain a.

futuM :: forall f a m. (HTraversable f, Monad m) => CVCoalgM m f a -> NatM m a (Term f) Source #

This function constructs the unique monadic futumorphism from the given monadic cv-coalgebra to the term algebra.