Copyright | (c) 2010-2011 Patrick Bahr |
---|---|

License | BSD3 |

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

Stability | experimental |

Portability | non-portable (GHC Extensions) |

Safe Haskell | None |

Language | Haskell98 |

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 ShowHF f where
- class KShow a where
- makeShowHF :: Name -> Q [Dec]
- class EqHF f where
- class KEq f where
- makeEqHF :: Name -> Q [Dec]
- class EqHF f => OrdHF f where
- makeOrdHF :: 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]

# 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 `ShowHF f`

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

.

Nothing

makeShowHF :: Name -> Q [Dec] Source

Derive an instance of `ShowHF`

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

## EqHF

Signature equality. An instance `EqHF f`

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

.

makeEqHF :: Name -> Q [Dec] Source

Derive an instance of `EqHF`

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

## OrdHF

class EqHF f => OrdHF f where Source

Signature ordering. An instance `OrdHF f`

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

.

makeOrdHF :: Name -> Q [Dec] Source

Derive an instance of `OrdHF`

for a type constructor of any parametric
kind taking at least three 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.