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 |
Data.Comp.Multi.Derive
Description
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]
- liftSum :: Name -> Q [Dec]
- makeGeneric :: [Name] -> [Type] -> Q [Dec]
- makeInstancesLike :: [Name] -> [Type] -> Q [Dec] -> Q [Dec]
- data GenericExample
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)
.
Minimal complete definition
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.
Minimal complete definition
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
(All HFoldable fs, All HFunctor fs) => HFoldable (Sum fs) Source # | |
Defined in Data.Comp.Multi.Ops Methods hfold :: Monoid m => Sum fs (K m) :=> m Source # hfoldMap :: forall m (a :: Type -> Type). Monoid m => (a :=> m) -> Sum fs a :=> m Source # hfoldr :: forall (a :: Type -> Type) b. (a :=> (b -> b)) -> b -> Sum fs a :=> b Source # hfoldl :: forall b (a :: Type -> Type). (b -> a :=> b) -> b -> Sum fs a :=> b Source # | |
HFoldable f => HFoldable (Cxt h f) Source # | |
Defined in Data.Comp.Multi.Term Methods hfold :: Monoid m => Cxt h f (K m) :=> m Source # hfoldMap :: forall m (a :: Type -> Type). Monoid m => (a :=> m) -> Cxt h f a :=> m Source # hfoldr :: forall (a :: Type -> Type) b. (a :=> (b -> b)) -> b -> Cxt h f a :=> b Source # hfoldl :: forall b (a :: Type -> Type). (b -> a :=> b) -> b -> Cxt h f a :=> b Source # | |
HFoldable f => HFoldable (f :&: a) Source # | |
Defined in Data.Comp.Multi.Ops Methods hfold :: Monoid m => (f :&: a) (K m) :=> m Source # hfoldMap :: forall m (a0 :: Type -> Type). Monoid m => (a0 :=> m) -> (f :&: a) a0 :=> m Source # hfoldr :: forall (a0 :: Type -> Type) b. (a0 :=> (b -> b)) -> b -> (f :&: a) a0 :=> b Source # hfoldl :: forall b (a0 :: Type -> Type). (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 # |
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
(All HTraversable fs, All HFoldable fs, All HFunctor fs) => HTraversable (Sum fs) Source # | |
Defined in Data.Comp.Multi.Ops | |
HTraversable f => HTraversable (Cxt h f) Source # | |
Defined in Data.Comp.Multi.Term Methods hmapM :: forall (m :: Type -> Type) (a :: Type -> Type) (b :: Type -> Type). Monad m => NatM m a b -> NatM m (Cxt h f a) (Cxt h f b) Source # htraverse :: forall (f0 :: Type -> Type) (a :: Type -> Type) (b :: Type -> Type). Applicative f0 => NatM f0 a b -> NatM f0 (Cxt h f a) (Cxt h f b) Source # | |
HTraversable f => HTraversable (f :&: a) Source # | |
Defined in Data.Comp.Multi.Ops Methods hmapM :: forall (m :: Type -> Type) (a0 :: Type -> Type) (b :: Type -> Type). Monad m => NatM m a0 b -> NatM m ((f :&: a) a0) ((f :&: a) b) Source # htraverse :: forall (f0 :: Type -> Type) (a0 :: Type -> Type) (b :: Type -> Type). Applicative f0 => NatM f0 a0 b -> NatM f0 ((f :&: a) a0) ((f :&: a) b) 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.
Lifting to Sums
liftSum :: Name -> Q [Dec] Source #
Given the name of a type class, where the first parameter is a higher-order
functor, lift it to sums of higher-order. Example: class HShowF f where ...
is lifted as instance (HShowF f, HShowF g) => HShowF (f :+: g) where ...
.
Generic
data GenericExample Source #