derive-2.6.2: A program and library to derive instances for data types

Safe HaskellNone
LanguageHaskell2010

Language.Haskell.TH.Helper

Contents

Description

These small short-named functions are intended to make the construction of abstranct syntax trees less tedious.

Synopsis

Special folds for the guessing

applyWith :: Exp -> [Exp] -> Exp #

foldl1With :: Exp -> [Exp] -> Exp #

foldr1With :: Exp -> [Exp] -> Exp #

Syntax elements

sclause :: [Pat] -> Exp -> Clause #

A simple clause, without where or guards.

defclause :: Int -> Exp -> Clause #

A default clause with N arguments.

sval :: Pat -> Exp -> Dec #

A simple Val clause

case' :: Exp -> [(Pat, Exp)] -> Exp #

(->:) :: String -> Exp -> Exp #

instance_none :: String -> DataDef -> [Dec] -> Dec #

We provide 3 standard instance constructors instance_default requires C for each free type variable instance_none requires no context instance_context requires a given context

simple_instance :: String -> DataDef -> [Dec] -> [Dec] #

Build an instance of a class for a data type, using the heuristic that the type is itself required on all type arguments.

generic_instance :: String -> DataDef -> [Type] -> [Dec] -> [Dec] #

Build an instance of a class for a data type, using the class at the given types

sigN :: String -> Type -> Dec #

Build a type signature declaration with a string name

funN :: String -> [Clause] -> Dec #

Build a fundecl with a string name

Pattern vs Value abstraction

class Eq nm => NameLike nm where #

Minimal complete definition

toName

Methods

toName :: nm -> Name #

Instances

NameLike Name # 

Methods

toName :: Name -> Name #

NameLike String # 

Methods

toName :: String -> Name #

class Valcon a where #

The class used to overload lifting operations. To reduce code duplication, we overload the wrapped constructors (and everything else, but that's irrelevant) to work in patterns, expressions, and types.

Minimal complete definition

lK, vr, raw_lit, tup, lst

Methods

lK :: NameLike nm => nm -> [a] -> a #

Build an application node, with a name for a head and a provided list of arguments.

vr :: NameLike nm => nm -> a #

Reference a named variable.

raw_lit :: Lit -> a #

Lift a TH Lit

tup :: [a] -> a #

Tupling

lst :: [a] -> a #

Listing

Instances

Valcon Exp # 

Methods

lK :: NameLike nm => nm -> [Exp] -> Exp #

vr :: NameLike nm => nm -> Exp #

raw_lit :: Lit -> Exp #

tup :: [Exp] -> Exp #

lst :: [Exp] -> Exp #

Valcon Pat # 

Methods

lK :: NameLike nm => nm -> [Pat] -> Pat #

vr :: NameLike nm => nm -> Pat #

raw_lit :: Lit -> Pat #

tup :: [Pat] -> Pat #

lst :: [Pat] -> Pat #

Valcon Type # 

Methods

lK :: NameLike nm => nm -> [Type] -> Type #

vr :: NameLike nm => nm -> Type #

raw_lit :: Lit -> Type #

tup :: [Type] -> Type #

lst :: [Type] -> Type #

app :: Exp -> [Exp] -> Exp #

Build an application node without a given head

class LitC a where #

This class is used to overload literal construction based on the type of the literal.

Minimal complete definition

lit

Methods

lit :: Valcon p => a -> p #

Instances

LitC Char # 

Methods

lit :: Valcon p => Char -> p #

LitC Integer # 

Methods

lit :: Valcon p => Integer -> p #

LitC () # 

Methods

lit :: Valcon p => () -> p #

LitC a => LitC [a] # 

Methods

lit :: Valcon p => [a] -> p #

(LitC a, LitC b) => LitC (a, b) # 

Methods

lit :: Valcon p => (a, b) -> p #

(LitC a, LitC b, LitC c) => LitC (a, b, c) # 

Methods

lit :: Valcon p => (a, b, c) -> p #

Constructor abstraction

vars :: Valcon a => Char -> Int -> [a] #

Common pattern: list of a familiy of variables

vrn :: Valcon a => Char -> Int -> a #

Variable based on a letter + number

ctv :: Valcon a => CtorDef -> Char -> [a] #

Make a list of variables, one for each argument to a constructor

ctp :: Valcon a => CtorDef -> Char -> a #

Make a simple pattern to bind a constructor

ctc :: Valcon a => CtorDef -> a #

Reference the constructor itself

Lift a constructor over a fixed number of arguments.

l0 :: (NameLike nm, Valcon a) => nm -> a #

l1 :: (NameLike nm, Valcon a) => nm -> a -> a #

l2 :: (NameLike nm, Valcon a) => nm -> a -> a -> a #

Pre-lifted versions of common operations

true :: Valcon a => a #

false :: Valcon a => a #

nil :: Valcon a => a #

id' :: Exp #

cons :: Valcon a => a -> a -> a #

box :: Valcon a => a -> a #

const' :: Exp -> Exp #

(==:) :: Exp -> Exp -> Exp #

(&&:) :: Exp -> Exp -> Exp #

(++:) :: Exp -> Exp -> Exp #

(>>=:) :: Exp -> Exp -> Exp #

(>>:) :: Exp -> Exp -> Exp #

(.:) :: Exp -> Exp -> Exp #

ap' :: Exp -> Exp -> Exp #

(>:) :: Exp -> Exp -> Exp #

hCons' :: Type -> Type -> Type #

(&&::) :: [Exp] -> Exp #

Build a chain of expressions, with an appropriate terminal sequence__ does not require a unit at the end (all others are optimised automatically)

(++::) :: [Exp] -> Exp #

Build a chain of expressions, with an appropriate terminal sequence__ does not require a unit at the end (all others are optimised automatically)

(>>::) :: [Exp] -> Exp #

Build a chain of expressions, with an appropriate terminal sequence__ does not require a unit at the end (all others are optimised automatically)

sequence__ :: [Exp] -> Exp #

Build a chain of expressions, with an appropriate terminal sequence__ does not require a unit at the end (all others are optimised automatically)

(.::) :: [Exp] -> Exp #

Build a chain of expressions, with an appropriate terminal sequence__ does not require a unit at the end (all others are optimised automatically)

liftmk :: Exp -> [Exp] -> Exp #

K-way liftM