compdata-param-0.9.2: Parametric Compositional Data Types

Copyright(c) 2011 Patrick Bahr Tom Hvitved
LicenseBSD3
MaintainerTom Hvitved <hvitved@diku.dk>
Stabilityexperimental
Portabilitynon-portable (GHC Extensions)
Safe HaskellNone
LanguageHaskell98

Data.Comp.Param.Derive

Contents

Description

This module contains functionality for automatically deriving boilerplate code using Template Haskell. Examples include instances of Difunctor, Difoldable, and Ditraversable.

Synopsis

Documentation

derive :: [Name -> Q [Dec]] -> [Name] -> Q [Dec] #

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

class EqD f where Source #

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.

Minimal complete definition

eqD

Methods

eqD :: PEq a => f Name a -> f Name a -> FreshM Bool Source #

Instances
(EqD f, EqD g) => EqD (f :+: g) Source #

EqD is propagated through sums.

Instance details

Defined in Data.Comp.Param.Equality

Methods

eqD :: PEq a => (f :+: g) Name a -> (f :+: g) Name a -> FreshM Bool Source #

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

From an EqD difunctor an Eq instance of the corresponding term type can be derived.

Instance details

Defined in Data.Comp.Param.Equality

Methods

eqD :: PEq a => Cxt h f Name a -> Cxt h f Name a -> FreshM Bool Source #

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 where Source #

Signature ordering. An instance OrdD f gives rise to an instance Ord (Term f).

Minimal complete definition

compareD

Methods

compareD :: POrd a => f Name a -> f Name a -> FreshM Ordering Source #

Instances
(OrdD f, OrdD g) => OrdD (f :+: g) Source #

OrdD is propagated through sums.

Instance details

Defined in Data.Comp.Param.Ordering

Methods

compareD :: POrd a => (f :+: g) Name a -> (f :+: g) Name a -> FreshM Ordering Source #

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

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

Instance details

Defined in Data.Comp.Param.Ordering

Methods

compareD :: POrd a => Cxt h f Name a -> Cxt h f Name a -> FreshM Ordering Source #

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

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

ShowD

class ShowD f where Source #

Signature printing. An instance ShowD f gives rise to an instance Show (Term f).

Minimal complete definition

showD

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

Defined in Data.Comp.Param.Show

Methods

showD :: (f :&: p) Name (FreshM String) -> FreshM String Source #

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

Defined in Data.Comp.Param.Show

Methods

showD :: (f :+: g) Name (FreshM String) -> FreshM String Source #

(Difunctor f, ShowD f) => ShowD (Cxt h f) Source #

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

Instance details

Defined in Data.Comp.Param.Show

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

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

Difunctor

class Difunctor f Source #

This class represents difunctors, i.e. binary type constructors that are contravariant in the first argument and covariant in the second argument.

Minimal complete definition

dimap

Instances
Difunctor ((->) :: * -> * -> *) Source #

The canonical example of a difunctor.

Instance details

Defined in Data.Comp.Param.Difunctor

Methods

dimap :: (a -> b) -> (c -> d) -> (b -> c) -> a -> d Source #

Difunctor f => Difunctor (f :&: p) Source # 
Instance details

Defined in Data.Comp.Param.Ops

Methods

dimap :: (a -> b) -> (c -> d) -> (f :&: p) b c -> (f :&: p) a d Source #

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

Defined in Data.Comp.Param.Ops

Methods

dimap :: (a -> b) -> (c -> d) -> (f :+: g) b c -> (f :+: g) a d Source #

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 => Ditraversable f Source #

Difunctors representing data structures that can be traversed from left to right.

Instances
Ditraversable f => Ditraversable (f :&: p) Source # 
Instance details

Defined in Data.Comp.Param.Ops

Methods

dimapM :: Monad m => (b -> m c) -> (f :&: p) a b -> m ((f :&: p) a c) Source #

disequence :: Monad m => (f :&: p) a (m b) -> m ((f :&: p) a b) Source #

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

Defined in Data.Comp.Param.Ops

Methods

dimapM :: Monad m => (b -> m c) -> (f :+: g) a b -> m ((f :+: g) a c) Source #

disequence :: Monad m => (f :+: g) a (m b) -> m ((f :+: g) a b) Source #

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 difunctor. The smart constructors are similar to the ordinary constructors, but a 'inject . dimap Var id' is automatically inserted.

Smart Constructors w/ Annotations

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

Derive smart constructors with annotations for a difunctor. The smart constructors are similar to the ordinary constructors, but a 'injectA . dimap Var id' is automatically inserted.

Lifting to Sums

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

Given the name of a type class, where the first parameter is a difunctor, lift it to sums of difunctors. Example: class ShowD f where ... is lifted as instance (ShowD f, ShowD g) => ShowD (f :+: g) where ... .