| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Origami.Internal.Build
Contents
Description
Builds fold declarations for a FoldFamily.
Documentation
Arguments
| :: [Name] | names of the root datatypes |
| -> [Name] | names of the n-ary functor classes to be used |
| -> [Name] | names of datatypes declared to be atomic |
| -> Q [Dec] |
First discovers the fold family by starting at the root datatypes and including their components' datatypes recursively, then builds declarations from it to be spliced into the source file.
Datatypes declared as atomic will not be recursed into and will not become part of the fold family.
In general, the framework does not currently handle parameterized
types, but applications of Traversable, Bitraversable, or
Tritraversable can be handled, if the user declares them. The
n-ary functors are treated as "transparent" and traversed
through. (You are not expected to understand this explanation: take
a look at the type signatures in the Haddock of the generated
code.)
The framework:
- Generates a parameterized
Foldrecord; each parameterxxxcorresponds to a non-atomic datatypeXxxin the fold family. Each fieldmkYyyof theFoldcorresponds to a constructorYyyused by some datatype in the fold family. - Generates an
idFoldrecord; folding overidFoldis equivalent to applyingid: it does nothing.idFoldis useful as a base record to build your own folds upon. - Generates an
errFoldfunction to create a taggedFoldrecord, with undefined fields that give a useful error message when accessed.mkXxx (errFold "example")is defined aserror "example.mkXxx". - Generates a
monadicFoldfunction that transforms aFoldinto one that applies the base fold monadically in a bottom-up, left-to-right way. (Again, see the Haddocks of the generated code.) - For each datatype
Xxx, generates afoldXxxfunction that applies aFoldto anXxxvalue, returning a value of typexxx.
The names Fold, idFold, errFold, and monadicFold are fixed.
They are intended to be imported qualified.
There are other restrictions not mentioned here: if you hit any of them, the framework should output a helpful, intelligible error message when generating the declarations before trying to splice and compile declarations. You should see no errors from the compiler trying to compile bad generated code.
buildFoldsDryRun :: [Name] -> [Name] -> [Name] -> Q [Dec] Source
Prints onto standard output the result of running buildFolds
but doesn't splice the fold declarations.
for testing
Errors possible while building a FoldFamily
buildFoldFamilyMaybe :: [Name] -> [Name] -> [Name] -> Q Exp Source
Builds a FoldFamily or returns an error. Spliced result is of
type Either BuildErr FoldFamily.