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

Stability | experimental |

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

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 PShow a where
- class ShowHD f where
- makeShowHD :: Name -> Q [Dec]
- class HDifunctor f
- makeHDifunctor :: Name -> Q [Dec]
- class HFunctor h => HFoldable h
- makeHFoldable :: Name -> Q [Dec]
- class HFoldable t => HTraversable t
- makeHTraversable :: 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

Printing of parametric values.

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.

## HFoldable

makeHFoldable :: Name -> Q [Dec]Source

Derive an instance of `HFoldable`

for a type constructor of any higher-order
kind taking at least two arguments.

## HTraversable

class HFoldable t => HTraversable t Source

HTraversable f => HTraversable (Cxt h f) | |

HTraversable f => HTraversable (:&: f a) | |

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

makeHTraversable :: Name -> Q [Dec]Source

Derive an instance of `HTraversable`

for a type constructor of any
higher-order kind taking at least two arguments.

## Smart Constructors

smartConstructors :: Name -> Q [Dec]Source

Derive smart constructors for a type constructor of any parametric kind
taking at least three arguments. The smart constructors are similar to the
ordinary constructors, but an `inject`

is automatically inserted.

## Smart Constructors w/ Annotations

smartAConstructors :: Name -> Q [Dec]Source

Derive smart constructors with products for a type constructor of any
parametric kind taking at least three arguments. The smart constructors are
similar to the ordinary constructors, but an `injectA`

is automatically
inserted.