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`

.

## Synopsis

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

.

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

class HFunctor h => HFoldable h Source #

## Instances

HFoldable f => HFoldable (Cxt h f) Source # | |

Defined in Data.Comp.Multi.Term | |

HFoldable f => HFoldable (f :&: a) Source # | |

Defined in Data.Comp.Multi.Ops hfold :: Monoid m => (f :&: a) (K m) :=> m Source # hfoldMap :: Monoid m => (a0 :=> m) -> (f :&: a) a0 :=> m Source # hfoldr :: (a0 :=> (b -> b)) -> b -> (f :&: a) a0 :=> b Source # hfoldl :: (b -> a0 :=> b) -> b -> (f :&: a) a0 :=> b Source # hfoldr1 :: (a0 -> a0 -> a0) -> (f :&: a) (K a0) :=> a0 Source # hfoldl1 :: (a0 -> a0 -> a0) -> (f :&: a) (K a0) :=> a0 Source # | |

(HFoldable f, HFoldable g) => HFoldable (f :+: g) Source # | |

Defined in Data.Comp.Multi.Ops |

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 #

## Instances

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

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

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

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.