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 Difunctor
,
Difoldable
, and Ditraversable
.
- derive :: [Name -> Q [Dec]] -> [Name] -> Q [Dec]
- class EqD f where
- makeEqD :: Name -> Q [Dec]
- class EqD f => OrdD f where
- makeOrdD :: Name -> Q [Dec]
- class PShow a where
- class ShowD f where
- makeShowD :: Name -> Q [Dec]
- class Difunctor f
- makeDifunctor :: Name -> Q [Dec]
- class (Difunctor f, Monad m) => Ditraversable f m a
- makeDitraversable :: Name -> Q [Dec]
- smartConstructors :: Name -> Q [Dec]
- smartAConstructors :: Name -> Q [Dec]
- liftSum :: Name -> Q [Dec]
- caseD :: (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 parametric signatures, i.e. signatures for parametric compositional data types.
EqD
Signature equality. An instance EqD f
gives rise to an instance
Eq (Term f)
. The equality test is performed inside the FreshM
monad for
generating fresh identifiers.
makeEqD :: Name -> Q [Dec]Source
Derive an instance of EqD
for a type constructor of any parametric
kind taking at least two arguments.
OrdD
class EqD f => OrdD f whereSource
Signature ordering. An instance OrdD f
gives rise to an instance
Ord (Term f)
.
makeOrdD :: Name -> Q [Dec]Source
Derive an instance of OrdD
for a type constructor of any parametric
kind taking at least two arguments.
ShowD
Printing of parametric values.
Signature printing. An instance ShowD f
gives rise to an instance
Show (Term f)
.
makeShowD :: Name -> Q [Dec]Source
Derive an instance of ShowD
for a type constructor of any parametric
kind taking at least two arguments.
Difunctor
This class represents difunctors, i.e. binary type constructors that are contravariant in the first argument and covariant in the second argument.
makeDifunctor :: Name -> Q [Dec]Source
Derive an instance of Difunctor
for a type constructor of any parametric
kind taking at least two arguments.
Ditraversable
class (Difunctor f, Monad m) => Ditraversable f m a Source
Difunctors representing data structures that can be traversed from left to right.
Ditraversable (->) [] Any | |
Ditraversable (->) Gen a | |
Ditraversable (->) Maybe Any | Functions of the type |
Ditraversable (->) Identity a | |
Ditraversable (->) (Either e) Any | |
Ditraversable (->) m Any => Ditraversable (->) (ListT m) Any | |
(Error e, Ditraversable (->) m Any) => Ditraversable (->) (ErrorT e m) Any | |
Ditraversable (->) m a => Ditraversable (->) (ReaderT r m) a | |
Ditraversable (->) m Any => Ditraversable (->) (StateT s m) Any | |
(Monoid w, Ditraversable (->) m Any) => Ditraversable (->) (WriterT w m) Any | |
(Monoid w, Ditraversable (->) m Any) => Ditraversable (->) (RWST r w s m) Any | |
Ditraversable f m a => Ditraversable (:&: f p) m a | |
(Ditraversable f m a, Ditraversable g m a) => Ditraversable (:+: f g) m a |
makeDitraversable :: Name -> Q [Dec]Source
Derive an instance of Traversable
for a type constructor of any
first-order kind taking at least one argument.
Smart Constructors
smartConstructors :: Name -> Q [Dec]Source
Derive smart constructors for a type constructor of any parametric 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.