regular-0.3.4.2: Generic programming library for regular datatypes.

Portabilitynon-portable
Stabilityexperimental
Maintainergenerics@haskell.org
Safe HaskellSafe-Inferred

Generics.Regular.Functions.Fold

Contents

Description

Summary: Generic folding and unfolding.

Synopsis

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.

Methods

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

Instances

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.

Methods

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

Instances

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.