Portability | non-portable (GHC Extensions) |
---|---|
Stability | experimental |
Maintainer | Patrick Bahr <paba@diku.dk> |
This module defines the notion of algebras and catamorphisms, and their generalizations to e.g. monadic versions and other (co)recursion schemes.
- type Alg f a = f a -> a
- free :: forall f h a b. Functor f => Alg f b -> (a -> b) -> Cxt h f a -> b
- cata :: forall f a. Functor f => Alg f a -> Term f -> a
- cata' :: Functor f => Alg f a -> Cxt h f a -> a
- appCxt :: Functor f => Context f (Cxt h f a) -> Cxt h f a
- type AlgM m f a = f a -> m a
- algM :: (Traversable f, Monad m) => AlgM m f a -> Alg f (m a)
- freeM :: forall h f a m b. (Traversable f, Monad m) => AlgM m f b -> (a -> m b) -> Cxt h f a -> m b
- cataM :: forall f m a. (Traversable f, Monad m) => AlgM m f a -> Term f -> m a
- cataM' :: forall h f a m. (Traversable f, Monad m) => AlgM m f a -> Cxt h f a -> m a
- type CxtFun f g = forall a h. Cxt h f a -> Cxt h g a
- type SigFun f g = forall a. f a -> g a
- type TermHom f g = SigFun f (Context g)
- appTermHom :: (Traversable f, Functor g) => TermHom f g -> CxtFun f g
- compTermHom :: (Functor g, Functor h) => TermHom g h -> TermHom f g -> TermHom f h
- appSigFun :: (Functor f, Functor g) => SigFun f g -> CxtFun f g
- compSigFun :: SigFun g h -> SigFun f g -> SigFun f h
- termHom :: Functor g => SigFun f g -> TermHom f g
- compAlg :: Functor g => Alg g a -> TermHom f g -> Alg f a
- compCoalg :: TermHom f g -> Coalg f a -> CVCoalg' g a
- compCVCoalg :: (Functor f, Functor g) => TermHom f g -> CVCoalg' f a -> CVCoalg' g a
- type CxtFunM m f g = forall a h. Cxt h f a -> m (Cxt h g a)
- type SigFunM m f g = forall a. f a -> m (g a)
- type TermHomM m f g = SigFunM m f (Context g)
- type SigFunM' m f g = forall a. f (m a) -> m (g a)
- type TermHomM' m f g = SigFunM' m f (Context g)
- sigFunM :: Monad m => SigFun f g -> SigFunM m f g
- termHom' :: (Functor f, Functor g, Monad m) => SigFunM m f g -> TermHomM m f g
- appTermHomM :: forall f g m. (Traversable f, Functor g, Monad m) => TermHomM m f g -> CxtFunM m f g
- termHomM :: (Functor g, Monad m) => SigFun f g -> TermHomM m f g
- termHomM' :: forall f g m. (Traversable f, Functor g, Monad m) => TermHomM' m f g -> CxtFunM m f g
- appSigFunM :: (Traversable f, Functor g, Monad m) => SigFunM m f g -> CxtFunM m f g
- appSigFunM' :: forall f g m. (Traversable f, Functor g, Monad m) => SigFunM' m f g -> CxtFunM m f g
- compTermHomM :: (Traversable g, Functor h, Monad m) => TermHomM m g h -> TermHomM m f g -> TermHomM m f h
- compSigFunM :: Monad m => SigFunM m g h -> SigFunM m f g -> SigFunM m f h
- compAlgM :: (Traversable g, Monad m) => AlgM m g a -> TermHomM m f g -> AlgM m f a
- compAlgM' :: (Traversable g, Monad m) => AlgM m g a -> TermHom f g -> AlgM m f a
- type Coalg f a = a -> f a
- ana :: forall a f. Functor f => Coalg f a -> a -> Term f
- ana' :: forall a f. Functor f => Coalg f a -> a -> Term f
- type CoalgM m f a = a -> m (f a)
- anaM :: forall a m f. (Traversable f, Monad m) => CoalgM m f a -> a -> m (Term f)
- type RAlg f a = f (Term f, a) -> a
- para :: Functor f => RAlg f a -> Term f -> a
- type RAlgM m f a = f (Term f, a) -> m a
- paraM :: (Traversable f, Monad m) => RAlgM m f a -> Term f -> m a
- type RCoalg f a = a -> f (Either (Term f) a)
- apo :: Functor f => RCoalg f a -> a -> Term f
- type RCoalgM m f a = a -> m (f (Either (Term f) a))
- apoM :: (Traversable f, Monad m) => RCoalgM m f a -> a -> m (Term f)
- type CVAlg f a f' = f (Term f') -> a
- histo :: (Functor f, DistProd f a f') => CVAlg f a f' -> Term f -> a
- type CVAlgM m f a f' = f (Term f') -> m a
- histoM :: (Traversable f, Monad m, DistProd f a f') => CVAlgM m f a f' -> Term f -> m a
- type CVCoalg f a = a -> f (Context f a)
- futu :: forall f a. Functor f => CVCoalg f a -> a -> Term f
- type CVCoalg' f a = a -> Context f a
- futu' :: forall f a. Functor f => CVCoalg' f a -> a -> Term f
- type CVCoalgM m f a = a -> m (f (Context f a))
- futuM :: forall f a m. (Traversable f, Monad m) => CVCoalgM m f a -> a -> m (Term f)
Algebras & Catamorphisms
free :: forall f h a b. Functor f => Alg f b -> (a -> b) -> Cxt h f a -> bSource
Construct a catamorphism for contexts over f
with holes of type a
, from
the given algebra.
cata :: forall f a. Functor f => Alg f a -> Term f -> aSource
Construct a catamorphism from the given algebra.
cata' :: Functor f => Alg f a -> Cxt h f a -> aSource
A generalisation of cata
from terms over f
to contexts over f
, where
the holes have the type of the algebra carrier.
appCxt :: Functor f => Context f (Cxt h f a) -> Cxt h f aSource
This function applies a whole context into another context.
Monadic Algebras & Catamorphisms
type AlgM m f a = f a -> m aSource
This type represents a monadic algebra. It is similar to Alg
but
the return type is monadic.
algM :: (Traversable f, Monad m) => AlgM m f a -> Alg f (m a)Source
Convert a monadic algebra into an ordinary algebra with a monadic carrier.
freeM :: forall h f a m b. (Traversable f, Monad m) => AlgM m f b -> (a -> m b) -> Cxt h f a -> m bSource
Construct a monadic catamorphism for contexts over f
with holes of type
a
, from the given monadic algebra.
cataM :: forall f m a. (Traversable f, Monad m) => AlgM m f a -> Term f -> m aSource
Construct a monadic catamorphism from the given monadic algebra.
cataM' :: forall h f a m. (Traversable f, Monad m) => AlgM m f a -> Cxt h f a -> m aSource
A generalisation of cataM
from terms over f
to contexts over f
, where
the holes have the type of the monadic algebra carrier.
Term Homomorphisms
appTermHom :: (Traversable f, Functor g) => TermHom f g -> CxtFun f gSource
Apply a term homomorphism recursively to a term/context.
compTermHom :: (Functor g, Functor h) => TermHom g h -> TermHom f g -> TermHom f hSource
Compose two term homomorphisms.
appSigFun :: (Functor f, Functor g) => SigFun f g -> CxtFun f gSource
This function applies a signature function to the given context.
compSigFun :: SigFun g h -> SigFun f g -> SigFun f hSource
This function composes two signature functions.
termHom :: Functor g => SigFun f g -> TermHom f gSource
Lifts the given signature function to the canonical term homomorphism.
compAlg :: Functor g => Alg g a -> TermHom f g -> Alg f aSource
Compose an algebra with a term homomorphism to get a new algebra.
compCoalg :: TermHom f g -> Coalg f a -> CVCoalg' g aSource
Compose a term homomorphism with a coalgebra to get a cv-coalgebra.
compCVCoalg :: (Functor f, Functor g) => TermHom f g -> CVCoalg' f a -> CVCoalg' g aSource
Compose a term homomorphism with a cv-coalgebra to get a new cv-coalgebra.
Monadic Term Homomorphisms
type CxtFunM m f g = forall a h. Cxt h f a -> m (Cxt h g a)Source
This type represents a monadic context function.
type SigFunM m f g = forall a. f a -> m (g a)Source
This type represents a monadic signature function.
type TermHomM m f g = SigFunM m f (Context g)Source
This type represents a monadic term homomorphism.
type SigFunM' m f g = forall a. f (m a) -> m (g a)Source
This type represents a monadic signature function. It is similar
to SigFunM
but has monadic values also in the domain.
type TermHomM' m f g = SigFunM' m f (Context g)Source
This type represents a monadic term homomorphism. It is similar to
TermHomM
but has monadic values also in the domain.
sigFunM :: Monad m => SigFun f g -> SigFunM m f gSource
Lift the given signature function to a monadic signature function. Note that term homomorphisms are instances of signature functions. Hence this function also applies to term homomorphisms.
termHom' :: (Functor f, Functor g, Monad m) => SigFunM m f g -> TermHomM m f gSource
Lift the give monadic signature function to a monadic term homomorphism.
appTermHomM :: forall f g m. (Traversable f, Functor g, Monad m) => TermHomM m f g -> CxtFunM m f gSource
Apply a monadic term homomorphism recursively to a term/context.
termHomM :: (Functor g, Monad m) => SigFun f g -> TermHomM m f gSource
Lift the given signature function to a monadic term homomorphism.
termHomM' :: forall f g m. (Traversable f, Functor g, Monad m) => TermHomM' m f g -> CxtFunM m f gSource
This function constructs the unique monadic homomorphism from the initial term algebra to the given term algebra.
appSigFunM :: (Traversable f, Functor g, Monad m) => SigFunM m f g -> CxtFunM m f gSource
This function applies a monadic signature function to the given context.
appSigFunM' :: forall f g m. (Traversable f, Functor g, Monad m) => SigFunM' m f g -> CxtFunM m f gSource
This function applies a signature function to the given context.
compTermHomM :: (Traversable g, Functor h, Monad m) => TermHomM m g h -> TermHomM m f g -> TermHomM m f hSource
Compose two monadic term homomorphisms.
compSigFunM :: Monad m => SigFunM m g h -> SigFunM m f g -> SigFunM m f hSource
This function composes two monadic signature functions.
compAlgM :: (Traversable g, Monad m) => AlgM m g a -> TermHomM m f g -> AlgM m f aSource
Compose a monadic algebra with a monadic term homomorphism to get a new monadic algebra.
compAlgM' :: (Traversable g, Monad m) => AlgM m g a -> TermHom f g -> AlgM m f aSource
Compose a monadic algebra with a term homomorphism to get a new monadic algebra.
Coalgebras & Anamorphisms
ana :: forall a f. Functor f => Coalg f a -> a -> Term fSource
Construct an anamorphism from the given coalgebra.
type CoalgM m f a = a -> m (f a)Source
This type represents a monadic coalgebra over a functor f
and carrier
a
.
anaM :: forall a m f. (Traversable f, Monad m) => CoalgM m f a -> a -> m (Term f)Source
Construct a monadic anamorphism from the given monadic coalgebra.
R-Algebras & Paramorphisms
type RAlg f a = f (Term f, a) -> aSource
This type represents an r-algebra over a functor f
and carrier a
.
para :: Functor f => RAlg f a -> Term f -> aSource
Construct a paramorphism from the given r-algebra.
type RAlgM m f a = f (Term f, a) -> m aSource
This type represents a monadic r-algebra over a functor f
and carrier
a
.
paraM :: (Traversable f, Monad m) => RAlgM m f a -> Term f -> m aSource
Construct a monadic paramorphism from the given monadic r-algebra.
R-Coalgebras & Apomorphisms
type RCoalg f a = a -> f (Either (Term f) a)Source
This type represents an r-coalgebra over a functor f
and carrier a
.
apo :: Functor f => RCoalg f a -> a -> Term fSource
Construct an apomorphism from the given r-coalgebra.
type RCoalgM m f a = a -> m (f (Either (Term f) a))Source
This type represents a monadic r-coalgebra over a functor f
and carrier
a
.
apoM :: (Traversable f, Monad m) => RCoalgM m f a -> a -> m (Term f)Source
Construct a monadic apomorphism from the given monadic r-coalgebra.
CV-Algebras & Histomorphisms
type CVAlg f a f' = f (Term f') -> aSource
This type represents a cv-algebra over a functor f
and carrier a
.
histo :: (Functor f, DistProd f a f') => CVAlg f a f' -> Term f -> aSource
Construct a histomorphism from the given cv-algebra.
type CVAlgM m f a f' = f (Term f') -> m aSource
This type represents a monadic cv-algebra over a functor f
and carrier
a
.
histoM :: (Traversable f, Monad m, DistProd f a f') => CVAlgM m f a f' -> Term f -> m aSource
Construct a monadic histomorphism from the given monadic cv-algebra.
CV-Coalgebras & Futumorphisms
type CVCoalg f a = a -> f (Context f a)Source
This type represents a cv-coalgebra over a functor f
and carrier a
.
futu :: forall f a. Functor f => CVCoalg f a -> a -> Term fSource
Construct a futumorphism from the given cv-coalgebra.
type CVCoalg' f a = a -> Context f aSource
This type represents a generalised cv-coalgebra over a functor f
and
carrier a
.
futu' :: forall f a. Functor f => CVCoalg' f a -> a -> Term fSource
Construct a futumorphism from the given generalised cv-coalgebra.