regular-0.2.4: Generic programming library for regular datatypes.





Summary: Generic folding and unfolding.


Generic folding

type family Alg f r :: *Source

type Algebra a r = Alg (PF a) rSource

class Fold f whereSource

The class fold explains how to convert an algebra Alg into a function from functor to result.


alg :: Alg f r -> f r -> rSource


Fold U 
Fold I 
Fold (K a) 
Fold f => Fold (S s f) 
Fold f => Fold (C c f) 
Fold g => Fold (:*: I g) 
Fold g => Fold (:*: (K a) g) 
(Fold f, Fold g) => Fold (:+: f g) 

fold :: (Regular a, Fold (PF a), Functor (PF a)) => Algebra a r -> a -> rSource

Fold with convenient algebras.

Generic unfolding

type family CoAlg f s :: *Source

type CoAlgebra a s = s -> CoAlg (PF a) sSource

class Unfold f whereSource

The class unfold explains how to convert a coalgebra CoAlg and a seed into a representation.


coalg :: (s -> a) -> CoAlg f s -> f aSource


Unfold U 
Unfold I 
Unfold (K a) 
Unfold f => Unfold (S s f) 
Unfold f => Unfold (C c f) 
(Unfold f, Unfold g) => Unfold (:*: f g) 
(Unfold f, Unfold g) => Unfold (:+: f g) 

unfold :: (Unfold (PF a), Regular a) => CoAlgebra a s -> s -> aSource

Construction of algebras

(&) :: a -> b -> (a, b)Source

For constructing algebras it is helpful to use this pairing combinator.