compdata-0.3: Compositional Data Types

Portabilitynon-portable (GHC Extensions)
MaintainerPatrick Bahr <>



This module defines the central notion of mutual recursive (or, higher-order) terms and its generalisation to (higher-order) contexts. All definitions are generalised versions of those in Data.Comp.Term.



data Cxt h f a i whereSource

This data type represents contexts over a signature. Contexts are terms containing zero or more holes. The first type parameter is supposed to be one of the phantom types Hole and NoHole. The second parameter is the signature of the context. The third parameter is the type family of the holes. The last parameter is the index/label.


Term :: f (Cxt h f a) i -> Cxt h f a i 
Hole :: a i -> Cxt Hole f a i 


(Ord v, HasVars f v, HFunctor f) => SubstVars v (Cxt h f a) (Cxt h f a) 
HFunctor f => HFunctor (Cxt h f) 
HFoldable f => HFoldable (Cxt h f) 
HTraversable f => HTraversable (Cxt h f) 
HEqF f => HEqF (Cxt h f)

From an EqF functor an Eq instance of the corresponding term type can be derived.

(HShowF f, HFunctor f) => HShowF (Cxt h f) 
HasVars f v => HasVars (Cxt h f) v 
(HEqF f, KEq a) => KEq (Cxt h f a) 
(HShowF f, HFunctor f, KShow a) => KShow (Cxt h f a) 

data Hole Source

Phantom type that signals that a Cxt might contain holes.

data NoHole Source

Phantom type that signals that a Cxt does not contain holes.

type Context = Cxt HoleSource

A context might contain holes.

data Nothing Source

Phantom type family used to define Term.


type Term f = Cxt NoHole f NothingSource

A (higher-order) term is a context with no holes.

type Const f = f (K ())Source

constTerm :: HFunctor f => Const f :-> Term fSource

This function converts a constant to a term. This assumes that the argument is indeed a constant, i.e. does not have a value for the argument type of the functor f.

unTerm :: Term f t -> f (Term f) tSource

This function unravels the given term at the topmost layer.

toCxt :: HFunctor f => Term f :-> Context f aSource

Cast a term over a signature to a context over the same signature.

simpCxt :: HFunctor f => f a i -> Context f a iSource