HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Moduleth-utilities-0.2.5.2Haskell2010

TH.Utilities

Miscellaneous Template Haskell utilities, added as needed by packages in the th-utilities repo and elsewhere.

Synopsis
valueunAppsT :: Type -> [Type]

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.

valuetupT :: [Q Type] -> Q Type

Given a list of types, produce the type of a tuple of those types. This is analogous to tupE and tupP.

tupT [[t|Int|], [t|Char|], [t|Bool]] = [t| (Int, Char, Bool) |]

@since FIXME

valuepromotedTupT :: [Q Type] -> Q Type

Given a list of types, produce the type of a promoted tuple of those types. This is analogous to tupE and tupP.

promotedTupT [[t|3|], [t| 'True|], [t|Bool]] = [t| '(3, 'True, Bool) |]

@since FIXME

valueexpectTyCon1 :: Name -> Type -> Q Type

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).

valueexpectTyCon2 :: Name -> Type -> Q (Type, Type)

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).

valuedequalify :: Name -> Name

Construct a plain name (mkName) based on the given name. This is useful for cases where TH doesn't expect a unique name.

datadata ExpLifter

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.

Note that this cannot be used in typed quotes, because liftTyped will throw an exception. This is because this hack is incompatible with the type of liftTyped, as it would require the generated code to have type ExpLifter.

Constructors

Instances1Lift

Print splices generated by a TH splice (the printing will happen during compilation, as a GHC warning). Useful for debugging.

For instance, you can dump splices generated with makeLenses by replacing a top-level invocation of makeLenses in your code with:

dumpSplices $ makeLenses ''Foo