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

Safe Haskell | None
Language | Haskell2010

Language.Haskell.TH.Helper

Contents

- Special folds for the guessing
- Syntax elements
- Pattern vs Value abstraction
- Constructor abstraction
- Lift a constructor over a fixed number of arguments.
- Pre-lifted versions of common operations

Description

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

Synopsis

- applyWith :: Exp -> [Exp] -> Exp
- foldl1With :: Exp -> [Exp] -> Exp
- foldr1With :: Exp -> [Exp] -> Exp
- sclause :: [Pat] -> Exp -> Clause
- defclause :: Int -> Exp -> Clause
- sval :: Pat -> Exp -> Dec
- case' :: Exp -> [(Pat, Exp)] -> Exp
- (->:) :: String -> Exp -> Exp
- instance_none :: String -> DataDef -> [Dec] -> Dec
- instance_default :: String -> DataDef -> [Dec] -> Dec
- instance_context :: [String] -> String -> DataDef -> [Dec] -> Dec
- simple_instance :: String -> DataDef -> [Dec] -> [Dec]
- generic_instance :: String -> DataDef -> [Type] -> [Dec] -> [Dec]
- sigN :: String -> Type -> Dec
- funN :: String -> [Clause] -> Dec
- class Eq nm => NameLike nm where
- class Valcon a where
- app :: Exp -> [Exp] -> Exp
- class LitC a where
- dataVars :: DataDef -> [Type]
- vars :: Valcon a => Char -> Int -> [a]
- vrn :: Valcon a => Char -> Int -> a
- ctv :: Valcon a => CtorDef -> Char -> [a]
- ctp :: Valcon a => CtorDef -> Char -> a
- ctc :: Valcon a => CtorDef -> a
- l0 :: (NameLike nm, Valcon a) => nm -> a
- l1 :: (NameLike nm, Valcon a) => nm -> a -> a
- l2 :: (NameLike nm, Valcon a) => nm -> a -> a -> a
- true :: Valcon a => a
- false :: Valcon a => a
- nil :: Valcon a => a
- hNil' :: Type
- hZero' :: Type
- unit :: Exp
- id' :: Exp
- cons :: Valcon a => a -> a -> a
- box :: Valcon a => a -> a
- return' :: Exp -> Exp
- const' :: Exp -> Exp
- hSucc' :: Type -> Type
- (==:) :: 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
- (++::) :: [Exp] -> Exp
- (>>::) :: [Exp] -> Exp
- sequence__ :: [Exp] -> Exp
- (.::) :: [Exp] -> Exp
- liftmk :: Exp -> [Exp] -> Exp

# Special folds for the guessing

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

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

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

# Syntax elements

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

A simple clause, without where or guards.

defclause :: Int -> Exp -> Clause Source #

A default clause with N arguments.

sval :: Pat -> Exp -> Dec Source #

A simple Val clause

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

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

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

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

instance_default :: String -> DataDef -> [Dec] -> Dec Source #

instance_context :: [String] -> String -> DataDef -> [Dec] -> Dec Source #

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

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

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

sigN :: String -> Type -> Dec Source #

Build a type signature declaration with a string name

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

Build a fundecl with a string name

# Pattern vs Value abstraction

class Eq nm => NameLike nm where Source #

Minimal complete definition

toName

Methods

toName :: nm -> Name Source #

Instances

NameLike Name Source # |
Methods toName :: Name -> Name Source #
NameLike String Source # |
Methods toName :: String -> Name Source #

class Valcon a where Source #

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

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

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

Reference a named variable.

raw_lit :: Lit -> a Source #

Lift a TH `Lit`

tup :: [a] -> a Source #

Tupling

lst :: [a] -> a Source #

Listing

Instances

Valcon Exp Source # |
Methods lK :: NameLike nm => nm -> [Exp] -> Exp Source # vr :: NameLike nm => nm -> Exp Source # raw_lit :: Lit -> Exp Source # tup :: [Exp] -> Exp Source # lst :: [Exp] -> Exp Source #
Valcon Pat Source # |
Methods lK :: NameLike nm => nm -> [Pat] -> Pat Source # vr :: NameLike nm => nm -> Pat Source # raw_lit :: Lit -> Pat Source # tup :: [Pat] -> Pat Source # lst :: [Pat] -> Pat Source #
Valcon Type Source # |
Methods lK :: NameLike nm => nm -> [Type] -> Type Source # vr :: NameLike nm => nm -> Type Source # raw_lit :: Lit -> Type Source # tup :: [Type] -> Type Source # lst :: [Type] -> Type Source #

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

Build an application node without a given head

class LitC a where Source #

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

Instances

LitC Char Source # |
Methods lit :: Valcon p => Char -> p Source #
LitC Integer Source # |
Methods lit :: Valcon p => Integer -> p Source #
LitC () Source # |
Methods lit :: Valcon p => () -> p Source #
LitC a => LitC [a] Source # |
Methods lit :: Valcon p => [a] -> p Source #
(LitC a, LitC b) => LitC (a, b) Source # |
Methods lit :: Valcon p => (a, b) -> p Source #
(LitC a, LitC b, LitC c) => LitC (a, b, c) Source # |
Methods lit :: Valcon p => (a, b, c) -> p Source #

# Constructor abstraction

dataVars :: DataDef -> [Type] Source #

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

Common pattern: list of a familiy of variables

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

Variable based on a letter + number

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

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

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

Make a simple pattern to bind a constructor

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

Reference the constructor itself

# Lift a constructor over a fixed number of arguments.

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

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

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

# Pre-lifted versions of common operations

true :: Valcon a => a Source #

false :: Valcon a => a Source #

nil :: Valcon a => a Source #

hNil' :: Type Source #

hZero' :: Type Source #

unit :: Exp Source #

id' :: Exp Source #

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

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

return' :: Exp -> Exp Source #

const' :: Exp -> Exp Source #

hSucc' :: Type -> Type Source #

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

K-way liftM