Copyright | (c) 2009--2010 Universiteit Utrecht |
---|---|
License | BSD3 |
Maintainer | generics@haskell.org |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe |
Language | Haskell2010 |
A variant of fold that allows the specification of the algebra in a convenient way.
Synopsis
- type family Alg (f :: (* -> *) -> * -> *) (r :: * -> *) (ix :: *) :: *
- type family Comp (f :: (* -> *) -> * -> *) (r :: * -> *) (ix :: *) :: *
- type Algebra phi r = forall ix. phi ix -> Alg (PF phi) r ix
- class Fold (f :: (* -> *) -> * -> *) where
- fold :: forall phi ix r. (Fam phi, HFunctor phi (PF phi), Fold (PF phi)) => Algebra phi r -> phi ix -> ix -> r ix
- (&) :: a -> b -> (a, b)
The type family of convenient algebras.
type family Alg (f :: (* -> *) -> * -> *) (r :: * -> *) (ix :: *) :: * Source #
The type family we use to describe the convenient algebras.
Instances
type Alg U r ix Source # | For a unit, no arguments are available. |
Defined in Generics.MultiRec.FoldAlg | |
type Alg (K a) r ix Source # | For a constant, we take the constant value to a result. |
Defined in Generics.MultiRec.FoldAlg | |
type Alg (I xi) r ix Source # | For an identity, we turn the recursive result into a final result. Note that the index can change. |
Defined in Generics.MultiRec.FoldAlg | |
type Alg (C c f) r ix Source # | Constructors are ignored. |
Defined in Generics.MultiRec.FoldAlg | |
type Alg (f :.: I xi) r ix Source # | |
Defined in Generics.MultiRec.FoldAlg | |
type Alg (f :>: xi) r ix Source # | A tag changes the index of the final result. |
Defined in Generics.MultiRec.FoldAlg | |
type Alg (f :*: g) r ix Source # | For a product where the left hand side is a constant, we take the value as an additional argument. |
Defined in Generics.MultiRec.FoldAlg | |
type Alg (f :+: g) r ix Source # | For a sum, the algebra is a pair of two algebras. |
Defined in Generics.MultiRec.FoldAlg |
type family Comp (f :: (* -> *) -> * -> *) (r :: * -> *) (ix :: *) :: * Source #
Instances
type Comp (K a) r ix Source # | |
Defined in Generics.MultiRec.FoldAlg | |
type Comp (I xi) r ix Source # | |
Defined in Generics.MultiRec.FoldAlg | |
type Comp (f :.: g) r ix Source # | |
Defined in Generics.MultiRec.FoldAlg |
type Algebra phi r = forall ix. phi ix -> Alg (PF phi) r ix Source #
The algebras passed to the fold have to work for all index types in the family. The additional witness argument is required only to make GHC's typechecker happy.
The class to turn convenient algebras into standard algebras.
class Fold (f :: (* -> *) -> * -> *) where Source #
The class fold explains how to convert a convenient algebra
Alg
back into a function from functor to result, as required
by the standard fold function.
Interface
fold :: forall phi ix r. (Fam phi, HFunctor phi (PF phi), Fold (PF phi)) => Algebra phi r -> phi ix -> ix -> r ix Source #
Fold with convenient algebras.