[Haskell-cafe] data declarations should provide fold functions

Johan Jeuring johanj at cs.uu.nl
Sat Jan 10 08:23:23 EST 2009


> I know the short-term answer is "use TH" to derive folds if
> I want them, but I think such an important concept should probably
> be part of the language.

The fold function is an example of a generic program, which can
be defined using generic programming libraries. Since the fold
has to know about the recursive structure of a datatype, not
all (actually, very few) generic programming libraries can be
used to define a fold.

An example of a recent library that can define folds is multirec
(developed by our own group, blatant self promotion):

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/multirec

A description of the library can be found in

http://www.cs.uu.nl/research/techreps/UU-CS-2008-019.html

Older generic programming approaches such as PolyP could define
the fold too, be it only for so-called regular (non mutually
recursive) datatypes. The multirec library defines folds for
mutually recursive datatypes.

The released version of multirec doesn't include the TH files
for generating the boilerplate code (for example, embedding-projection
pairs for datatypes) necessary for using the library. However,
the head has TH support for this.

All the best,

Johan Jeuring

> Tim Newsham
> http://www.thenewsh.com/~newsham/
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list