HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulelift-type-0.1.2.0Haskell2010

LiftType

Template Haskell has a class Lift that allows you to promote values from Haskell-land into the land of metaprogramming - Q.

class Lift a where
    lift :: a -> Q Exp

    liftTyped :: a -> Q (TExp a)

However, there wasn't a way to promote a *type* into a Q Type.

This library provides exactly that function. It requires a Typeable constraint, but this is automatically satisfied by GHC.

  • 1 type
  • 6 values
  • Packagelift-type-0.1.2.0
  • Exports7
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceLiftType.hs
valueliftType :: Typeable t => Type
#

Convert a type argument into a Template Haskell Type.

Use with TypeApplications.

Example:

>>> :set -XTypeApplications
>>> liftType @Bool
ConT GHC.Types.Bool
>>> liftType @[Char]
AppT (ConT GHC.Types.[]) (ConT GHC.Types.Char)

This works with data kinds, too.

>>> :set -XDataKinds
>>> liftType @3
LitT (NumTyLit 3)
>>> liftType @"hello"
LitT (StrTyLit "hello")
>>> liftType @'[Int, Char]
AppT (AppT (PromotedT GHC.Types.:) (ConT GHC.Types.Int)) (AppT (AppT (PromotedT GHC.Types.:) (ConT GHC.Types.Char)) (PromotedT GHC.Types.[]))
>>> liftType @'(Int, Char)
AppT (AppT (PromotedT GHC.Tuple.(,)) (ConT GHC.Types.Int)) (ConT GHC.Types.Char)

This function returns the name of the outermost type constructor.

Example5 expressions
typeToName @CharTypeName ''ChartypeToName @MaybeTypeName ''MaybetypeToName @(Maybe Char)TypeName ''MaybetypeToName @(Int -> Char)TypeName ''(->)typeToName @'FalsePromotedDataName 'False