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 `HDifunctor`

,
`ShowHD`

, and `EqHD`

.

- derive :: [Name -> Q [Dec]] -> [Name] -> Q [Dec]
- class EqHD f where
- makeEqHD :: Name -> Q [Dec]
- class EqHD f => OrdHD f where
- makeOrdHD :: Name -> Q [Dec]
- class ShowHD f where
- makeShowHD :: Name -> Q [Dec]
- class HDifunctor f
- makeHDifunctor :: Name -> Q [Dec]
- smartConstructors :: Name -> Q [Dec]
- smartAConstructors :: Name -> Q [Dec]
- liftSum :: Name -> Q [Dec]
- caseHD :: (f a b i -> c) -> (g a b i -> c) -> (f :+: g) a b i -> 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.

## EqHD

Signature equality. An instance `EqHD f`

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

. The equality test is performed inside the `FreshM`

monad for
generating fresh identifiers.

makeEqHD :: Name -> Q [Dec]Source

Derive an instance of `EqHD`

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

## OrdHD

class EqHD f => OrdHD f whereSource

Signature ordering. An instance `OrdHD f`

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

.

makeOrdHD :: Name -> Q [Dec]Source

Derive an instance of `OrdHD`

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

## ShowHD

Signature printing. An instance `ShowHD f`

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

.

makeShowHD :: Name -> Q [Dec]Source

Derive an instance of `ShowHD`

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

## HDifunctor

class HDifunctor f Source

This class represents higher-order difunctors.

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

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

makeHDifunctor :: Name -> Q [Dec]Source

Derive an instance of `HDifunctor`

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

## Smart Constructors

smartConstructors :: Name -> Q [Dec]Source

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

## Smart Constructors w/ Annotations

smartAConstructors :: Name -> Q [Dec]Source

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