th-extras-0.0.0.5: A grab bag of functions for use with Template Haskell
Safe HaskellNone
LanguageHaskell2010

Language.Haskell.TH.Extras

Synopsis

Documentation

replace :: (a -> Maybe a) -> a -> a 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

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 ([TyVarBndrUnit], 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.