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

Stability | experimental |

Maintainer | Patrick Bahr <paba@diku.dk> |

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

,
`HFoldable`

, and `HTraversable`

.

- derive :: [Name -> Q [Dec]] -> [Name] -> Q [Dec]
- class HShowF f where
- class KShow a where
- makeHShowF :: Name -> Q [Dec]
- class HEqF f where
- class KEq f where
- makeHEqF :: Name -> Q [Dec]
- class HFunctor h
- makeHFunctor :: 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]
- caseH :: (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 higher-order signatures, i.e. signatures for generalised compositional data types.

## HShowF

Signature printing. An instance `HShowF f`

gives rise to an instance
`KShow (HTerm f)`

.

makeHShowF :: Name -> Q [Dec]Source

Derive an instance of `HShowF`

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

## HEqF

Signature equality. An instance `HEqF f`

gives rise to an instance
`KEq (HTerm f)`

.

makeHEqF :: Name -> Q [Dec]Source

Derive an instance of `HEqF`

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

## HFunctor

This class represents higher-order functors (Johann, Ghani, POPL '08) which are endofunctors on the category of endofunctors.

makeHFunctor :: Name -> Q [Dec]Source

Derive an instance of `HFunctor`

for a type constructor of any higher-order
kind taking at least two 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 higher-order kind
taking at least two 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 two arguments. The smart constructors are
similar to the ordinary constructors, but an `injectA`

is automatically
inserted.