[Haskell-cafe] data declarations should provide fold functions
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):
A description of the library can be found in
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,
> Tim Newsham
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe