category-extras-0.53.5: Various modules and constructs inspired by category theory

Portabilitynon-portable (rank-2 polymorphism)
MaintainerEdward Kmett <>



Algebras, Coalgebras, Bialgebras, and Dialgebras and their (co)monadic variants



type Dialgebra f g a = f a -> g aSource

F,G-dialgebras generalize algebras and coalgebras NB: these definitions are actually wrong.

type GDialgebra f g w m a = f (w a) -> g (m a)Source

type Bialgebra f g a = (Algebra f a, Coalgebra g a)Source

F-G-bialgebras are representable by DiAlg (f :+: Identity) (Identity :+: g) a and so add no expressive power, but are a lot more convenient.

type GBialgebra f g w m a = (GAlgebra f w a, GCoalgebra g m a)Source

type Algebra f a = f a -> aSource


type GAlgebra f w a = f (w a) -> aSource

F-W-Comonadic Algebras for a given comonad W

type Coalgebra f a = a -> f aSource


type GCoalgebra f m a = a -> f (m a)Source

F-M-Monadic Coalgebras for a given monad M

type Trialgebra f g h a = (Algebra f a, Dialgebra g h a)Source

Martin Erwig's trialgebras for indexed data types

liftAlgebra :: (Functor f, Comonad w) => Algebra f :~> GAlgebra f wSource

Turn an F-algebra into a F-W-algebra by throwing away the comonad

liftCoalgebra :: (Functor f, Monad m) => Coalgebra f :~> GCoalgebra f mSource

Turn a F-coalgebra into a F-M-coalgebra by returning into a monad