Safe Haskell | None |
---|---|
Language | Haskell2010 |
Miscellaneous Template Haskell utilities, added as needed by packages in the th-utilities repo and elsewhere.
- tyVarBndrName :: TyVarBndr -> Name
- unAppsT :: Type -> [Type]
- typeToNamedCon :: Type -> Maybe (Name, [Type])
- expectTyCon1 :: Name -> Type -> Q Type
- expectTyCon2 :: Name -> Type -> Q (Type, Type)
- proxyE :: TypeQ -> ExpQ
- dequalify :: Name -> Name
- freeVarsT :: Type -> [Name]
- plainInstanceD :: Cxt -> Type -> [Dec] -> Dec
- fromPlainInstanceD :: Dec -> Maybe (Cxt, Type, [Dec])
- data ExpLifter = ExpLifter ExpQ
Documentation
unAppsT :: Type -> [Type] Source
Breaks a type application like A b c
into [A, b, c]. In other
words, it descends leftwards down AppT
constructors, and yields a
list of the results.
expectTyCon1 :: Name -> Type -> Q Type Source
Expect the provided type to be an application of a regular type to
one argument, otherwise fail with a message. This will also work if
the name is a promoted data constructor (PromotedT
).
expectTyCon2 :: Name -> Type -> Q (Type, Type) Source
Expect the provided type to be an application of a regular type to
two arguments, otherwise fail with a message. This will also work if
the name is a promoted data constructor (PromotedT
).
dequalify :: Name -> Name Source
Construct a plain name (mkName
) based on the given name. This is
useful for cases where TH doesn't expect a unique name.
plainInstanceD :: Cxt -> Type -> [Dec] -> Dec Source
Utility to conveniently handle change to InstanceD
API in
template-haskell-2.11.0
fromPlainInstanceD :: Dec -> Maybe (Cxt, Type, [Dec]) Source
Utility to conveniently handle change to InstanceD
API in
template-haskell-2.11.0
Hack to enable putting expressions inside lift
-ed TH data. For
example, you could do
main = print $(lift [ExpLifter [e| 1 + 1 |], ExpLifter [e| 2 |]])
Here, lift
is working on a value of type [ExpLifter]
. The code
generated by lift
constructs a list with the ExpLifter
expressions providing the element values.
Without ExpLifter
, lift
tends to just generate code involving
data construction. With ExpLifter
, you can put more complicated
expression into this construction.