th-extras-0.0.0.8: A grab bag of functions for use with Template Haskell

Safe Haskell | None
Language | Haskell2010

Language.Haskell.TH.Extras

Synopsis

- intIs64 :: Bool
- replace :: (a -> Maybe a) -> a -> a
- composeExprs :: [ExpQ] -> ExpQ
- nameOfCon :: Con -> Name
- argTypesOfCon :: Con -> [Type]
- nameOfBinder :: TyVarBndr_ a -> Name
- varsBoundInCon :: Con -> [TyVarBndrSpec]
- namesBoundInPat :: Pat -> [Name]
- namesBoundInDec :: Dec -> [Name]
- genericalizeName :: Name -> Name
- genericalizeDecs :: [Dec] -> [Dec]
- headOfType :: Type -> Name
- occursInType :: Name -> Type -> Bool
- substVarsWith :: [Name] -> Type -> Type -> Type
- kindArity :: Kind -> Int
- tyConArity :: Name -> Q Int
- tyConArity' :: Name -> Q ([TyVarBndr BndrVis], Int)
- decCons :: Dec -> [Con]
- conArity :: Con -> Int

# Documentation

intIs64 :: Bool Source #

replace :: (a -> Maybe a) -> a -> a Source #

composeExprs :: [ExpQ] -> ExpQ Source #

nameOfCon :: Con -> Name Source #

Determines the name of a data constructor. It's an error if the `Con` binds more than one name (which happens in the case where you use GADT syntax, and give multiple data constructor names separated by commas in a type signature in the where clause).

argTypesOfCon :: Con -> [Type] Source #

WARNING: discards binders in GADTs and existentially-quantified constructors

nameOfBinder :: TyVarBndr_ a -> Name Source #

varsBoundInCon :: Con -> [TyVarBndrSpec] Source #

namesBoundInPat :: Pat -> [Name] Source #

namesBoundInDec :: Dec -> [Name] Source #

genericalizeName :: Name -> Name Source #

genericalizeDecs :: [Dec] -> [Dec] Source #

headOfType :: Type -> Name Source #

occursInType :: Name -> Type -> Bool Source #

substVarsWith :: [Name] -> Type -> Type -> Type Source #

Assuming that we're building an instance of the form C (T v_1 ... v_(n-1)) for some GADT T, this function takes a list of the variables v_1 ... v_(n-1) used in the instance head, as well as the result type of some data constructor, say T x_1 ... x_(n-1) x_n, as well as the type t of some argument to it, and substitutes any of x_i (1 <= i <= n-1) occurring in t for the corresponding v_i, taking care to avoid name capture by foralls in t.

kindArity :: Kind -> Int Source #

Determine the arity of a kind. Starting in template-haskell 2.8.0.0, `Kind` and `Type` became synonymous.

tyConArity :: Name -> Q Int Source #

Given the name of a type constructor, determine its full arity

tyConArity' :: Name -> Q ([TyVarBndr BndrVis], Int) Source #

Given the name of a type constructor, determine a list of type variables bound as parameters by its declaration, and the arity of the kind of type being defined (i.e. how many more arguments would need to be supplied in addition to the bound parameters in order to obtain an ordinary type of kind *). If the supplied `Name` is anything other than a data or newtype, produces an error.

decCons :: Dec -> [Con] Source #

Determine the constructors bound by a data or newtype declaration. Errors out if supplied with another sort of declaration.

conArity :: Con -> Int Source #

Determine the arity of a data constructor.