compdata-0.13.0: Compositional Data Types
Copyright(c) 2010-2011 Patrick Bahr
LicenseBSD3
MaintainerPatrick Bahr <paba@diku.dk>
Stabilityexperimental
Portabilitynon-portable (GHC Extensions)
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

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

class ShowHF f where Source #

Signature printing. An instance ShowHF f gives rise to an instance KShow (HTerm f).

Minimal complete definition

Nothing

Instances

Instances details
(ShowHF f, HFunctor f) => ShowHF (Cxt h f) Source # 
Instance details

Defined in Data.Comp.Multi.Show

Methods

showHF :: Alg (Cxt h f) (K String) Source #

showHF' :: Cxt h f (K String) :=> String Source #

(ShowHF f, Show p) => ShowHF (f :&: p) Source # 
Instance details

Defined in Data.Comp.Multi.Show

Methods

showHF :: Alg (f :&: p) (K String) Source #

showHF' :: (f :&: p) (K String) :=> String Source #

(ShowHF f, ShowHF g) => ShowHF (f :+: g) Source # 
Instance details

Defined in Data.Comp.Multi.Show

Methods

showHF :: Alg (f :+: g) (K String) Source #

showHF' :: (f :+: g) (K String) :=> String Source #

class KShow a where Source #

Methods

kshow :: a i -> K String i Source #

Instances

Instances details
KShow (K String) Source # 
Instance details

Defined in Data.Comp.Multi.Show

Methods

kshow :: K String i -> K String i Source #

KShow (K ()) Source # 
Instance details

Defined in Data.Comp.Multi.Show

Methods

kshow :: K () i -> K String i Source #

(ShowHF f, HFunctor f, KShow a) => KShow (Cxt h f a) Source # 
Instance details

Defined in Data.Comp.Multi.Show

Methods

kshow :: Cxt h f a i -> K String i Source #

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

class EqHF f where Source #

Signature equality. An instance EqHF f gives rise to an instance KEq (HTerm f).

Methods

eqHF :: KEq g => f g i -> f g j -> Bool Source #

Instances

Instances details
EqHF f => EqHF (Cxt h f) Source # 
Instance details

Defined in Data.Comp.Multi.Equality

Methods

eqHF :: forall (g :: Type -> Type) i j. KEq g => Cxt h f g i -> Cxt h f g j -> Bool Source #

(EqHF f, EqHF g) => EqHF (f :+: g) Source #

EqF is propagated through sums.

Instance details

Defined in Data.Comp.Multi.Equality

Methods

eqHF :: forall (g0 :: Type -> Type) i j. KEq g0 => (f :+: g) g0 i -> (f :+: g) g0 j -> Bool Source #

class KEq f where Source #

Methods

keq :: f i -> f j -> Bool Source #

Instances

Instances details
Eq a => KEq (K a) Source # 
Instance details

Defined in Data.Comp.Multi.Equality

Methods

keq :: K a i -> K a j -> Bool Source #

(EqHF f, KEq a) => KEq (Cxt h f a) Source # 
Instance details

Defined in Data.Comp.Multi.Equality

Methods

keq :: Cxt h f a i -> Cxt h f a j -> Bool Source #

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

Methods

compareHF :: KOrd a => f a i -> f a j -> Ordering Source #

Instances

Instances details
(HFunctor f, OrdHF f) => OrdHF (Cxt h f) Source #

From an OrdHF difunctor an Ord instance of the corresponding term type can be derived.

Instance details

Defined in Data.Comp.Multi.Ordering

Methods

compareHF :: forall (a :: Type -> Type) i j. KOrd a => Cxt h f a i -> Cxt h f a j -> Ordering Source #

(OrdHF f, OrdHF g) => OrdHF (f :+: g) Source #

OrdHF is propagated through sums.

Instance details

Defined in Data.Comp.Multi.Ordering

Methods

compareHF :: forall (a :: Type -> Type) i j. KOrd a => (f :+: g) a i -> (f :+: g) a j -> Ordering Source #

makeOrdHF :: Name -> Q [Dec] Source #

Derive an instance of OrdHF for a type constructor of any parametric kind taking at least three arguments.

HFunctor

class HFunctor h Source #

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

Minimal complete definition

hfmap

Instances

Instances details
HFunctor f => HFunctor (Cxt h f) Source # 
Instance details

Defined in Data.Comp.Multi.Term

Methods

hfmap :: forall (f0 :: Type -> Type) (g :: Type -> Type). (f0 :-> g) -> Cxt h f f0 :-> Cxt h f g Source #

Functor f => HFunctor (Compose f :: (Type -> Type) -> Type -> Type) Source # 
Instance details

Defined in Data.Comp.Multi.HFunctor

Methods

hfmap :: forall (f0 :: Type -> Type) (g :: Type -> Type). (f0 :-> g) -> Compose f f0 :-> Compose f g Source #

HFunctor f => HFunctor (f :&: a) Source # 
Instance details

Defined in Data.Comp.Multi.Ops

Methods

hfmap :: forall (f0 :: Type -> Type) (g :: Type -> Type). (f0 :-> g) -> (f :&: a) f0 :-> (f :&: a) g Source #

(HFunctor f, HFunctor g) => HFunctor (f :+: g) Source # 
Instance details

Defined in Data.Comp.Multi.Ops

Methods

hfmap :: forall (f0 :: Type -> Type) (g0 :: Type -> Type). (f0 :-> g0) -> (f :+: g) f0 :-> (f :+: g) g0 Source #

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 #

Higher-order functors that can be folded.

Minimal complete definition: hfoldMap or hfoldr.

Instances

Instances details
HFoldable f => HFoldable (Cxt h f) Source # 
Instance details

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 #

hfoldr1 :: (a -> a -> a) -> Cxt h f (K a) :=> a Source #

hfoldl1 :: (a -> a -> a) -> Cxt h f (K a) :=> a Source #

HFoldable f => HFoldable (f :&: a) Source # 
Instance details

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 #

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

Defined in Data.Comp.Multi.Ops

Methods

hfold :: Monoid m => (f :+: g) (K m) :=> m Source #

hfoldMap :: forall m (a :: Type -> Type). Monoid m => (a :=> m) -> (f :+: g) a :=> m Source #

hfoldr :: forall (a :: Type -> Type) b. (a :=> (b -> b)) -> b -> (f :+: g) a :=> b Source #

hfoldl :: forall b (a :: Type -> Type). (b -> a :=> b) -> b -> (f :+: g) a :=> b Source #

hfoldr1 :: (a -> a -> a) -> (f :+: g) (K a) :=> a Source #

hfoldl1 :: (a -> a -> a) -> (f :+: g) (K a) :=> a 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 #

Minimal complete definition

hmapM, htraverse

Instances

Instances details
HTraversable f => HTraversable (Cxt h f) Source # 
Instance details

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 # 
Instance details

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 #

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

Defined in Data.Comp.Multi.Ops

Methods

hmapM :: forall (m :: Type -> Type) (a :: Type -> Type) (b :: Type -> Type). Monad m => NatM m a b -> NatM m ((f :+: g) a) ((f :+: g) b) Source #

htraverse :: forall (f0 :: Type -> Type) (a :: Type -> Type) (b :: Type -> Type). Applicative f0 => NatM f0 a b -> NatM f0 ((f :+: g) a) ((f :+: g) 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.

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.

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 ... .