compdata-0.11: Compositional Data Types

Copyright(c) 2010-2011 Patrick Bahr
LicenseBSD3
MaintainerPatrick Bahr <paba@diku.dk>
Stabilityexperimental
Portabilitynon-portable (GHC Extensions)
Safe HaskellNone
LanguageHaskell98

Data.Comp.Multi.Derive

Contents

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

class KShow a where Source #

Minimal complete definition

kshow

Methods

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

Minimal complete definition

eqHF

Methods

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

Instances

EqHF f => EqHF (Cxt h f) Source # 

Methods

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

Methods

eqHF :: KEq g => (* :+: f) g g i -> (* :+: f) g g j -> Bool Source #

class KEq f where Source #

Minimal complete definition

keq

Methods

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

Instances

Eq a => KEq (K a) Source # 

Methods

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

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

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

Minimal complete definition

compareHF

Methods

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

Instances

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

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

Methods

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

Methods

compareHF :: 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

HFunctor f => HFunctor (Cxt h f) Source # 

Methods

hfmap :: (f :-> g) -> Cxt h f f :-> Cxt h f g Source #

Functor f => HFunctor (Compose * * f) Source # 

Methods

hfmap :: (f :-> g) -> Compose * * f f :-> Compose * * f g Source #

HFunctor f => HFunctor ((:&:) * f a) Source # 

Methods

hfmap :: (f :-> g) -> (* :&: f) a f :-> (* :&: f) a g Source #

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

Methods

hfmap :: (f :-> g) -> (* :+: f) g f :-> (* :+: f) g g 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

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

Methods

hfold :: Monoid m => Cxt h f (K m) :=> m Source #

hfoldMap :: Monoid m => (a :=> m) -> Cxt h f a :=> m Source #

hfoldr :: (a :=> (b -> b)) -> b -> Cxt h f a :=> b Source #

hfoldl :: (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 # 

Methods

hfold :: Monoid m => (* :&: f) a (K m) :=> m Source #

hfoldMap :: Monoid m => (a :=> m) -> (* :&: f) a a :=> m Source #

hfoldr :: (a :=> (b -> b)) -> b -> (* :&: f) a a :=> b Source #

hfoldl :: (b -> a :=> b) -> b -> (* :&: f) a a :=> b Source #

hfoldr1 :: (a -> a -> a) -> (* :&: f) a (K a) :=> a Source #

hfoldl1 :: (a -> a -> a) -> (* :&: f) a (K a) :=> a Source #

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

Methods

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

hfoldMap :: Monoid m => (a :=> m) -> (* :+: f) g a :=> m Source #

hfoldr :: (a :=> (b -> b)) -> b -> (* :+: f) g a :=> b Source #

hfoldl :: (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

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

Methods

hmapM :: Monad m => NatM m a b -> NatM m (Cxt h f a) (Cxt h f b) Source #

htraverse :: Applicative f => NatM f a b -> NatM f (Cxt h f a) (Cxt h f b) Source #

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

Methods

hmapM :: Monad m => NatM m a b -> NatM m ((* :&: f) a a) ((* :&: f) a b) Source #

htraverse :: Applicative f => NatM f a b -> NatM f ((* :&: f) a a) ((* :&: f) a b) Source #

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

Methods

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

htraverse :: Applicative f => NatM f a b -> NatM f ((* :+: 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 ... .