Portability | non-portable (GHC Extensions) |
---|---|

Stability | experimental |

Maintainer | Tom Hvitved <hvitved@diku.dk> |

Safe Haskell | Safe-Infered |

This module contains functionality for automatically deriving boilerplate
code using Template Haskell. Examples include instances of `Difunctor`

,
`Difoldable`

, and `Ditraversable`

.

- derive :: [Name -> Q [Dec]] -> [Name] -> Q [Dec]
- class EqD f where
- makeEqD :: Name -> Q [Dec]
- class EqD f => OrdD f where
- makeOrdD :: Name -> Q [Dec]
- class ShowD f where
- makeShowD :: Name -> Q [Dec]
- class Difunctor f
- makeDifunctor :: Name -> Q [Dec]
- class Difunctor f => Ditraversable f
- makeDitraversable :: Name -> Q [Dec]
- smartConstructors :: Name -> Q [Dec]
- smartAConstructors :: Name -> Q [Dec]
- liftSum :: Name -> Q [Dec]
- caseD :: (f a b -> c) -> (g a b -> c) -> (f :+: g) a b -> c

# Documentation

derive :: [Name -> Q [Dec]] -> [Name] -> Q [Dec]Source

Helper function for generating a list of instances for a list of named
signatures. For example, in order to derive instances `Functor`

and
`ShowF`

for a signature `Exp`

, use derive as follows (requires Template
Haskell):

$(derive [makeFunctor, makeShowF] [''Exp])

Derive boilerplate instances for parametric signatures, i.e. signatures for parametric compositional data types.

## EqD

Signature equality. An instance `EqD f`

gives rise to an instance
`Eq (Term f)`

. The equality test is performed inside the `FreshM`

monad for
generating fresh identifiers.

makeEqD :: Name -> Q [Dec]Source

Derive an instance of `EqD`

for a type constructor of any parametric
kind taking at least two arguments.

## OrdD

class EqD f => OrdD f whereSource

Signature ordering. An instance `OrdD f`

gives rise to an instance
`Ord (Term f)`

.

makeOrdD :: Name -> Q [Dec]Source

Derive an instance of `OrdD`

for a type constructor of any parametric
kind taking at least two arguments.

## ShowD

Signature printing. An instance `ShowD f`

gives rise to an instance
`Show (Term f)`

.

makeShowD :: Name -> Q [Dec]Source

Derive an instance of `ShowD`

for a type constructor of any parametric
kind taking at least two arguments.

## Difunctor

This class represents difunctors, i.e. binary type constructors that are contravariant in the first argument and covariant in the second argument.

makeDifunctor :: Name -> Q [Dec]Source

Derive an instance of `Difunctor`

for a type constructor of any parametric
kind taking at least two arguments.

## Ditraversable

class Difunctor f => Ditraversable f Source

Difunctors representing data structures that can be traversed from left to right.

Ditraversable f => Ditraversable (:&: f p) | |

(Ditraversable f, Ditraversable g) => Ditraversable (:+: f g) |

makeDitraversable :: Name -> Q [Dec]Source

Derive an instance of `Traversable`

for a type constructor of any
first-order kind taking at least one argument.

## Smart Constructors

smartConstructors :: Name -> Q [Dec]Source

Derive smart constructors for a difunctor. The smart constructors are similar to the ordinary constructors, but a 'inject . dimap Var id' is automatically inserted.

## Smart Constructors w/ Annotations

smartAConstructors :: Name -> Q [Dec]Source

Derive smart constructors with annotations for a difunctor. The smart constructors are similar to the ordinary constructors, but a 'injectA . dimap Var id' is automatically inserted.