HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduletemplate-haskell-2.22.0.0Haskell2010

Language.Haskell.TH

The public face of Template Haskell

For other documentation, refer to: https://wiki.haskell.org/Template_Haskell

  • 66 types
  • 2 classes
  • 49 values

The monad and its operations

3 declarations
newtypenewtype Q a
#
Instances10Monad, Functor, MonadFix, MonadFail, Applicative, Quote, …
  • Monad QDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • Functor QDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • MonadFix QDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax

    If the function passed to mfix inspects its argument, the resulting action will throw a FixIOException.

  • MonadFail QDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • Applicative QDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • Quote QDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • MonadIO QDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • Quasi QDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • Semigroup a => Semigroup (Q a)Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • Monoid a => Monoid (Q a)Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
classclass Monad m => Quote (m :: Type -> Type) where
#

The Quote class implements the minimal interface which is necessary for desugaring quotations.

  • The Monad m superclass is needed to stitch together the different AST fragments.

  • newName is used when desugaring binding structures such as lambdas to generate fresh names.

Therefore the type of an untyped quotation in GHC is `Quote m => m Exp`

For many years the type of a quotation was fixed to be `Q Exp` but by more precisely specifying the minimal interface it enables the Exp to be extracted purely from the quotation without interacting with Q.

Methods

  • newName :: String -> m Name

    Generate a fresh name, which cannot be captured.

    For example, this:

    f = $(do
        nm1 <- newName "x"
        let nm2 = mkName "x"
        return (LamE [VarP nm1] (LamE [VarP nm2] (VarE nm1)))
       )

    will produce the splice

    f = \x0 -> \x -> x0

    In particular, the occurrence VarE nm1 refers to the binding VarP nm1, and is not captured by the binding VarP nm2.

    Although names generated by newName cannot be captured, they can capture other names. For example, this:

    g = $(do
      nm1 <- newName "x"
      let nm2 = mkName "x"
      return (LamE [VarP nm2] (LamE [VarP nm1] (VarE nm2)))
     )

    will produce the splice

    g = \x -> \x0 -> x0

    since the occurrence VarE nm2 is captured by the innermost binding of x, namely VarP nm1.

Instances2Quote
  • Quote IODefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • Quote QDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax

Administration: errors, locations and IO

valuereportError :: String -> Q ()
#

Report an error to the user, but allow the current splice's computation to carry on. To abort the computation, use fail.

valuereport :: Bool -> String -> Q ()
#

Deprecated. Use reportError or reportWarning instead

Report an error (True) or warning (False), but carry on; use fail to stop.

valuerecover
  1. :: Q a

    handler to invoke on failure

  2. -> Q a

    computation to run

  3. -> Q a
#

Recover from errors raised by reportError or fail.

valuelocation :: Q Loc
#

The location at which this computation is spliced.

datadata Loc
#
Instances7Eq, Data, Ord, Show, Generic, Ppr, …
valuerunIO :: IO a -> Q a
#

The runIO function lets you run an I/O computation in the Q monad. Take care: you are guaranteed the ordering of calls to runIO within a single Q computation, but not about the order in which splices are run.

Note: for various murky reasons, stdout and stderr handles are not necessarily flushed when the compiler finishes running, so you should flush them yourself.

Querying the compiler

Reify

valuereify :: Name -> Q Info
#

reify looks up information about the Name. It will fail with a compile error if the Name is not visible. A Name is visible if it is imported or defined in a prior top-level declaration group. See the documentation for newDeclarationGroup for more details.

It is sometimes useful to construct the argument name using lookupTypeName or lookupValueName to ensure that we are reifying from the right namespace. For instance, in this context:

data D = D

which D does reify (mkName "D") return information about? (Answer: D-the-type, but don't rely on it.) To ensure we get information about D-the-value, use lookupValueName:

do
  Just nm <- lookupValueName "D"
  reify nm

and to get information about D-the-type, use lookupTypeName.

valuenewDeclarationGroup :: Q [Dec]
#

Template Haskell is capable of reifying information about types and terms defined in previous declaration groups. Top-level declaration splices break up declaration groups.

For an example, consider this code block. We define a datatype X and then try to call reify on the datatype.

module Check where

data X = X
    deriving Eq

$(do
    info <- reify ''X
    runIO $ print info
 )

This code fails to compile, noting that X is not available for reification at the site of reify. We can fix this by creating a new declaration group using an empty top-level splice:

data X = X
    deriving Eq

$(pure [])

$(do
    info <- reify ''X
    runIO $ print info
 )

We provide newDeclarationGroup as a means of documenting this behavior and providing a name for the pattern.

Since top level splices infer the presence of the $( ... ) brackets, we can also write:

data X = X
    deriving Eq

newDeclarationGroup

$(do
    info <- reify ''X
    runIO $ print info
 )
datadata Info
#

Obtained from reify in the Q Monad.

Constructors

  • ClassI Dec [InstanceDec]

    A class, with a list of its visible instances

  • ClassOpI Name Type ParentName

    A class method

  • TyConI Dec

    A "plain" type constructor. "Fancier" type constructors are returned using PrimTyConI or FamilyI as appropriate. At present, this reified declaration will never have derived instances attached to it (if you wish to check for an instance, see reifyInstances).

  • FamilyI Dec [InstanceDec]

    A type or data family, with a list of its visible instances. A closed type family is returned with 0 instances.

  • PrimTyConI Name Arity Unlifted

    A "primitive" type constructor, which can't be expressed with a Dec. Examples: (->), Int#.

  • DataConI Name Type ParentName

    A data constructor

  • PatSynI Name PatSynType

    A pattern synonym

  • VarI Name Type (Maybe Dec)

    A "value" variable (as opposed to a type variable, see TyVarI).

    The Maybe Dec field contains Just the declaration which defined the variable - including the RHS of the declaration - or else Nothing, in the case where the RHS is unavailable to the compiler. At present, this value is always Nothing: returning the RHS has not yet been implemented because of lack of interest.

  • TyVarI Name Type

    A type variable.

    The Type field contains the type which underlies the variable. At present, this is always VarT theName, but future changes may permit refinement of this.

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata ModuleInfo
#

Obtained from reifyModule in the Q Monad.

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …

Language extension lookup

datadata Extension
#

The language extensions known to GHC.

Note that there is an orphan Binary instance for this type supplied by the GHC.LanguageExtensions module provided by ghc-boot. We can't provide here as this would require adding transitive dependencies to the template-haskell package, which must have a minimal dependency set.

CppOverlappingInstancesUndecidableInstancesIncoherentInstancesUndecidableSuperClassesMonomorphismRestrictionMonoLocalBindsDeepSubsumptionRelaxedPolyRecExtendedDefaultRulesForeignFunctionInterfaceUnliftedFFITypesInterruptibleFFICApiFFIGHCForeignImportPrimJavaScriptFFIParallelArraysArrowsTemplateHaskellTemplateHaskellQuotesQualifiedDoQuasiQuotesImplicitParamsImplicitPreludeScopedTypeVariablesAllowAmbiguousTypesUnboxedTuplesUnboxedSumsUnliftedNewtypesUnliftedDatatypesBangPatternsTypeFamiliesTypeFamilyDependenciesTypeInTypeOverloadedStringsOverloadedListsNumDecimalsDisambiguateRecordFieldsRecordWildCardsNamedFieldPunsViewPatternsGADTsGADTSyntaxNPlusKPatternsDoAndIfThenElseBlockArgumentsRebindableSyntaxConstraintKindsPolyKindsDataKindsTypeDataInstanceSigsApplicativeDoLinearTypesRequiredTypeArgumentsStandaloneDerivingDeriveDataTypeableAutoDeriveTypeableDeriveFunctorDeriveTraversableDeriveFoldableDeriveGenericDefaultSignaturesDeriveAnyClassDeriveLiftDerivingStrategiesDerivingViaTypeSynonymInstancesFlexibleContextsFlexibleInstancesConstrainedClassMethodsMultiParamTypeClassesNullaryTypeClassesFunctionalDependenciesUnicodeSyntaxExistentialQuantificationMagicHashEmptyDataDeclsKindSignaturesRoleAnnotationsParallelListCompTransformListCompMonadComprehensionsGeneralizedNewtypeDerivingRecursiveDoPostfixOperatorsTupleSectionsPatternGuardsLiberalTypeSynonymsRankNTypesImpredicativeTypesTypeOperatorsExplicitNamespacesPackageImportsExplicitForAllAlternativeLayoutRuleAlternativeLayoutRuleTransitionalDatatypeContextsNondecreasingIndentationRelaxedLayoutTraditionalRecordSyntaxLambdaCaseMultiWayIfBinaryLiteralsNegativeLiteralsHexFloatLiteralsDuplicateRecordFieldsOverloadedLabelsEmptyCasePatternSynonymsPartialTypeSignaturesNamedWildCardsStaticPointersTypeApplicationsStrictStrictDataEmptyDataDerivingNumericUnderscoresQuantifiedConstraintsStarIsTypeImportQualifiedPostCUSKsStandaloneKindSignaturesLexicalNegationFieldSelectorsOverloadedRecordDotOverloadedRecordUpdateTypeAbstractionsExtendedLiteralsListTuplePuns
Instances7Bounded, Enum, Eq, Ord, Show, Generic, …

Name lookup

valuelookupTypeName :: String -> Q (Maybe Name)
#

Look up the given name in the (type namespace of the) current splice's scope. See Language.Haskell.TH.Syntax#namelookup for more details.

valuelookupValueName :: String -> Q (Maybe Name)
#

Look up the given name in the (value namespace of the) current splice's scope. See Language.Haskell.TH.Syntax#namelookup for more details.

Fixity lookup

valuereifyFixity :: Name -> Q (Maybe Fixity)
#

reifyFixity nm attempts to find a fixity declaration for nm. For example, if the function foo has the fixity declaration infixr 7 foo, then reifyFixity 'foo would return Just (Fixity 7 InfixR). If the function bar does not have a fixity declaration, then reifyFixity 'bar returns Nothing, so you may assume bar has defaultFixity.

Type lookup

valuereifyType :: Name -> Q Type
#

reifyType nm attempts to find the type or kind of nm. For example, reifyType 'not returns Bool -> Bool, and reifyType ''Bool returns Type. This works even if there's no explicit signature and the type or kind is inferred.

Instance lookup

valuereifyInstances :: Name -> [Type] -> Q [InstanceDec]
#

reifyInstances nm tys returns a list of all visible instances (see below for "visible") of nm tys. That is, if nm is the name of a type class, then all instances of this class at the types tys are returned. Alternatively, if nm is the name of a data family or type family, all instances of this family at the types tys are returned.

Note that this is a "shallow" test; the declarations returned merely have instance heads which unify with nm tys, they need not actually be satisfiable.

  • reifyInstances ''Eq [ TupleT 2 `AppT` ConT ''A `AppT` ConT ''B ] contains the instance (Eq a, Eq b) => Eq (a, b) regardless of whether A and B themselves implement Eq

  • reifyInstances ''Show [ VarT (mkName "a") ] produces every available instance of Show

There is one edge case: reifyInstances ''Typeable tys currently always produces an empty list (no matter what tys are given).

In principle, the *visible* instances are * all instances defined in a prior top-level declaration group (see docs on newDeclarationGroup), or * all instances defined in any module transitively imported by the module being compiled

However, actually searching all modules transitively below the one being compiled is unreasonably expensive, so reifyInstances will report only the instance for modules that GHC has had some cause to visit during this compilation. This is a shortcoming: reifyInstances might fail to report instances for a type that is otherwise unusued, or instances defined in a different component. You can work around this shortcoming by explicitly importing the modules whose instances you want to be visible. GHC issue #20529 has some discussion around this.

valueisInstance :: Name -> [Type] -> Q Bool
#

Is the list of instances returned by reifyInstances nonempty?

If you're confused by an instance not being visible despite being defined in the same module and above the splice in question, see the docs for newDeclarationGroup for a possible explanation.

Roles lookup

valuereifyRoles :: Name -> Q [Role]
#

reifyRoles nm returns the list of roles associated with the parameters (both visible and invisible) of the tycon nm. Fails if nm cannot be found or is not a tycon. The returned list should never contain InferR.

An invisible parameter to a tycon is often a kind parameter. For example, if we have

type Proxy :: forall k. k -> Type
data Proxy a = MkProxy

and reifyRoles Proxy, we will get [NominalR, PhantomR]. The NominalR is the role of the invisible k parameter. Kind parameters are always nominal.

Annotation lookup

valuereifyAnnotations :: Data a => AnnLookup -> Q [a]
#

reifyAnnotations target returns the list of annotations associated with target. Only the annotations that are appropriately typed is returned. So if you have Int and String annotations for the same target, you have to call this function twice.

datadata AnnLookup
#

Annotation target for reifyAnnotations

Instances6Eq, Data, Ord, Show, Generic, Rep

Constructor strictness lookup

reifyConStrictness nm looks up the strictness information for the fields of the constructor with the name nm. Note that the strictness information that reifyConStrictness returns may not correspond to what is written in the source code. For example, in the following data declaration:

data Pair a = Pair a a

reifyConStrictness would return [DecidedLazy, DecidedLazy] under most circumstances, but it would return [DecidedStrict, DecidedStrict] if the -XStrictData language extension was enabled.

Typed expressions

10 declarations
newtypenewtype TExp (a :: TYPE r)
#

Typed wrapper around an Exp.

This is the typed representation of terms produced by typed quotes.

Representation-polymorphic since template-haskell-2.16.0.0.

valueunType :: TExp a -> Exp
#

Underlying untyped Template Haskell expression

newtypenewtype Code (m :: Type -> Type) (a :: TYPE r)
#

Represents an expression which has type a, built in monadic context m. Built on top of TExp, typed expressions allow for type-safe splicing via:

  • typed quotes, written as [|| ... ||] where ... is an expression; if that expression has type a, then the quotation has type Quote m => Code m a

  • typed splices inside of typed quotes, written as $$(...) where ... is an arbitrary expression of type Quote m => Code m a

Traditional expression quotes and splices let us construct ill-typed expressions:

Example2 expressions
fmap ppr $ runQ (unTypeCode [| True == $( [| "foo" |] ) |])GHC.Types.True GHC.Classes.== "foo"GHC.Types.True GHC.Classes.== "foo"<interactive> error:    • Couldn't match expected type ‘Bool’ with actual type ‘[Char]’    • In the second argument of ‘(==)’, namely ‘"foo"’      In the expression: True == "foo"      In an equation for ‘it’: it = True == "foo"

With typed expressions, the type error occurs when constructing the Template Haskell expression:

Example1 expression
fmap ppr $ runQ (unTypeCode [|| True == $$( [|| "foo" ||] ) ||])<interactive> error:    • Couldn't match type ‘[Char]’ with ‘Bool’      Expected type: Code Q Bool        Actual type: Code Q [Char]    • In the Template Haskell quotation [|| "foo" ||]      In the expression: [|| "foo" ||]      In the Template Haskell splice $$([|| "foo" ||])

Constructors

valueunTypeCode :: Quote m => Code m a -> m Exp
#

Extract the untyped representation from the typed representation

valuehoistCode :: Monad m => (forall x. m x -> n x) -> Code m a -> Code n a
#

Modify the ambient monad used during code generation. For example, you can use hoistCode to handle a state effect: handleState :: Code (StateT Int Q) a -> Code Q a handleState = hoistCode (flip runState 0)

valuebindCode :: Monad m => m a -> (a -> Code m b) -> Code m b
#

Variant of (>>=) which allows effectful computations to be injected into code generation.

valuebindCode_ :: Monad m => m a -> Code m b -> Code m b
#

Variant of (>>) which allows effectful computations to be injected into code generation.

valuejoinCode :: Monad m => m (Code m a) -> Code m a
#

A useful combinator for embedding monadic actions into Code myCode :: ... => Code m a myCode = joinCode $ do x <- someSideEffect return (makeCodeWith x)

valueliftCode :: m (TExp a) -> Code m a
#

Lift a monadic action producing code into the typed Code representation

Names

2 declarations
datadata Name
#

An abstract type representing names in the syntax tree.

Names can be constructed in several ways, which come with different name-capture guarantees (see Language.Haskell.TH.Syntax#namecapture for an explanation of name capture):

  • the built-in syntax 'f and ''T can be used to construct names, The expression 'f gives a Name which refers to the value f currently in scope, and ''T gives a Name which refers to the type T currently in scope. These names can never be captured.

  • lookupValueName and lookupTypeName are similar to 'f and ''T respectively, but the Names are looked up at the point where the current splice is being run. These names can never be captured.

  • newName monadically generates a new name, which can never be captured.

  • mkName generates a capturable name.

Names constructed using newName and mkName may be used in bindings (such as let x = ... or x -> ...), but names constructed using lookupValueName, lookupTypeName, 'f, ''T may not.

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata NameSpace
#
Instances6Eq, Data, Ord, Show, Generic, Rep

Constructing names

valuemkName :: String -> Name
#

Generate a capturable name. Occurrences of such names will be resolved according to the Haskell scoping rules at the occurrence site.

For example:

f = [| pi + $(varE (mkName "pi")) |]
...
g = let pi = 3 in $f

In this case, g is desugared to

g = Prelude.pi + 3

Note that mkName may be used with qualified names:

mkName "Prelude.pi"

See also dyn for a useful combinator. The above example could be rewritten using dyn as

f = [| pi + $(dyn "pi") |]

Deconstructing names

valuenameBase :: Name -> String
#

The name without its module prefix.

Examples
Example3 expressions
nameBase ''Data.Either.Either"Either"nameBase (mkName "foo")"foo"nameBase (mkName "Module.foo")"foo"
valuenameModule :: Name -> Maybe String
#

Module prefix of a name, if it exists.

Examples
Example3 expressions
nameModule ''Data.Either.EitherJust "Data.Either"nameModule (mkName "foo")NothingnameModule (mkName "Module.foo")Just "Module"
valuenamePackage :: Name -> Maybe String
#

A name's package, if it exists.

Examples
Example3 expressions
namePackage ''Data.Either.EitherJust "base"namePackage (mkName "foo")NothingnamePackage (mkName "Module.foo")Nothing
valuenameSpace :: Name -> Maybe NameSpace
#

Returns whether a name represents an occurrence of a top-level variable (VarName), data constructor (DataName), type constructor, or type class (TcClsName). If we can't be sure, it returns Nothing.

Examples
Example5 expressions
nameSpace 'Prelude.idJust VarNamenameSpace (mkName "id")Nothing -- only works for top-level variable namesnameSpace 'Data.Maybe.JustJust DataNamenameSpace ''Data.Maybe.MaybeJust TcClsNamenameSpace ''Data.Ord.OrdJust TcClsName

Built-in names

The algebraic data types

0 declarations

The lowercase versions (syntax operators) of these constructors are preferred to these constructors, since they compose better with quotations ([| |]) and splices ($( ... ))

Declarations

datadata Dec
#

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata Con
#

A data constructor.

The constructors for Con can roughly be divided up into two categories: those for constructors with "vanilla" syntax (NormalC, RecC, and InfixC), and those for constructors with GADT syntax (GadtC and RecGadtC). The ForallC constructor, which quantifies additional type variables and class contexts, can surround either variety of constructor. However, the type variables that it quantifies are different depending on what constructor syntax is used:

  • If a ForallC surrounds a constructor with vanilla syntax, then the ForallC will only quantify existential type variables. For example:

  data Foo a = forall b. MkFoo a b
  

In MkFoo, ForallC will quantify b, but not a.

  • If a ForallC surrounds a constructor with GADT syntax, then the ForallC will quantify all type variables used in the constructor. For example:

  data Bar a b where
    MkBar :: (a ~ b) => c -> MkBar a b
  

In MkBar, ForallC will quantify a, b, and c.

Multiplicity annotations for data types are currently not supported in Template Haskell (i.e. all fields represented by Template Haskell will be linear).

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata Clause
#

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata SourceUnpackedness
#

SourceUnpackedness corresponds to unpack annotations found in the source code.

This may not agree with the annotations returned by reifyConStrictness. See reifyConStrictness for more information.

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata SourceStrictness
#

SourceStrictness corresponds to strictness annotations found in the source code.

This may not agree with the annotations returned by reifyConStrictness. See reifyConStrictness for more information.

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata DecidedStrictness
#

Unlike SourceStrictness and SourceUnpackedness, DecidedStrictness refers to the strictness annotations that the compiler chooses for a data constructor field, which may be different from what is written in source code.

Note that non-unpacked strict fields are assigned DecidedLazy when a bang would be inappropriate, such as the field of a newtype constructor and fields that have an unlifted type.

See reifyConStrictness for more information.

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata Bang
#

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata Foreign
#
Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata Callconv
#
Instances6Eq, Data, Ord, Show, Generic, Rep
datadata Safety
#
Instances6Eq, Data, Ord, Show, Generic, Rep
datadata Pragma
#
Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata Inline
#
Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata RuleMatch
#
Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata Phases
#
Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata RuleBndr
#
Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata AnnTarget
#
Instances6Eq, Data, Ord, Show, Generic, Rep
datadata FunDep
#

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata TySynEqn
#

One equation of a type family instance or closed type family. The arguments are the left-hand-side type and the right-hand-side result.

For instance, if you had the following type family:

type family Foo (a :: k) :: k where
  forall k (a :: k). Foo @k a = a

The Foo @k a = a equation would be represented as follows:

TySynEqn (Just [PlainTV k, KindedTV a (VarT k)])
           (AppT (AppKindT (ConT ''Foo) (VarT k)) (VarT a))
           (VarT a)

Constructors

Instances6Eq, Data, Ord, Show, Generic, Rep
datadata TypeFamilyHead
#

Common elements of OpenTypeFamilyD and ClosedTypeFamilyD. By analogy with "head" for type classes and type class instances as defined in Type classes: an exploration of the design space, the TypeFamilyHead is defined to be the elements of the declaration between type family and where.

Instances6Eq, Data, Ord, Show, Generic, Rep
datadata Fixity
#
Instances6Eq, Data, Ord, Show, Generic, Rep
datadata FixityDirection
#
Instances6Eq, Data, Ord, Show, Generic, Rep
datadata NamespaceSpecifier
#

A way to specify a namespace to look in when GHC needs to find a name's source

Constructors

  • NoNamespaceSpecifier

    Name may be everything; If there are two names in different namespaces, then consider both

  • TypeNamespaceSpecifier

    Name should be a type-level entity, such as a data type, type alias, type family, type class, or type variable

  • DataNamespaceSpecifier

    Name should be a term-level entity, such as a function, data constructor, or pattern synonym

Instances6Eq, Data, Ord, Show, Generic, Rep
datadata PatSynDir
#

A pattern synonym's directionality.

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata PatSynArgs
#

A pattern synonym's argument type.

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …

Expressions

datadata Exp
#

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata Match
#

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata Body
#

Constructors

Instances6Eq, Data, Ord, Show, Generic, Rep
datadata Guard
#

Constructors

Instances6Eq, Data, Ord, Show, Generic, Rep
datadata Stmt
#

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata Range
#
Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata Lit
#

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …

Patterns

datadata Pat
#

Pattern in Haskell given in {}

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …

Types

datadata Type
#

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata TyVarBndr flag
#

The flag type parameter is instantiated to one of the following types:

Constructors

Instances10Functor, Foldable, Traversable, Eq, Data, Ord, …
datadata TyLit
#

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
typetype Kind = Type
#

To avoid duplication between kinds and types, they are defined to be the same. Naturally, you would never have a type be StarT and you would never have a kind be SigT, but many of the other constructors are shared. Note that the kind Bool is denoted with ConT, not PromotedT. Similarly, tuple kinds are made with TupleT, not PromotedTupleT.

typetype Pred = Type
#

Since the advent of ConstraintKinds, constraints are really just types. Equality constraints use the EqualityT constructor. Constraints may also be tuples of other constraints.

datadata Role
#

Role annotations

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata Specificity
#
Instances8Eq, Data, Ord, Show, Generic, DefaultBndrFlag, …
datadata BndrVis
#

Constructors

Instances8Eq, Data, Ord, Show, Generic, DefaultBndrFlag, …
datadata FamilyResultSig
#

Type family result signature

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
datadata InjectivityAnn
#

Injectivity annotation

Constructors

Instances7Eq, Data, Ord, Show, Generic, Ppr, …
typetype PatSynType = Type
#

A pattern synonym's type. Note that a pattern synonym's fully specified type has a peculiar shape coming with two forall quantifiers and two constraint contexts. For example, consider the pattern synonym

pattern P x1 x2 ... xn = <some-pattern>

P's complete type is of the following form

pattern P :: forall universals.   required constraints
          => forall existentials. provided constraints
          => t1 -> t2 -> ... -> tn -> t

consisting of four parts:

  1. the (possibly empty lists of) universally quantified type variables and required constraints on them.

  2. the (possibly empty lists of) existentially quantified type variables and the provided constraints on them.

  3. the types t1, t2, .., tn of x1, x2, .., xn, respectively

  4. the type t of <some-pattern>, mentioning only universals.

Pattern synonym types interact with TH when (a) reifying a pattern synonym, (b) pretty printing, or (c) specifying a pattern synonym's type signature explicitly:

  • Reification always returns a pattern synonym's fully specified type in abstract syntax.

  • Pretty printing via pprPatSynType abbreviates a pattern synonym's type unambiguously in concrete syntax: The rule of thumb is to print initial empty universals and the required context as () =>, if existentials and a provided context follow. If only universals and their required context, but no existentials are specified, only the universals and their required context are printed. If both or none are specified, so both (or none) are printed.

  • When specifying a pattern synonym's type explicitly with PatSynSigD either one of the universals, the existentials, or their contexts may be left empty.

See the GHC user's guide for more information on pattern synonyms and their types: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#pattern-synonyms.

Documentation

valueputDoc :: DocLoc -> String -> Q ()
#

Add Haddock documentation to the specified location. This will overwrite any documentation at the location if it already exists. This will reify the specified name, so it must be in scope when you call it. If you want to add documentation to something that you are currently splicing, you can use addModFinalizer e.g.

do
  let nm = mkName "x"
  addModFinalizer $ putDoc (DeclDoc nm) "Hello"
  [d| $(varP nm) = 42 |]

The helper functions withDecDoc and withDecsDoc will do this for you, as will the funD_doc and other _doc combinators. You most likely want to have the -haddock flag turned on when using this. Adding documentation to anything outside of the current module will cause an error.

valuegetDoc :: DocLoc -> Q (Maybe String)
#

Retrieves the Haddock documentation at the specified location, if one exists. It can be used to read documentation on things defined outside of the current module, provided that those modules were compiled with the -haddock flag.

datadata DocLoc
#

A location at which to attach Haddock documentation. Note that adding documentation to a Name defined oustide of the current module will cause an error.

Constructors

Instances6Eq, Data, Ord, Show, Generic, Rep

Library functions

0 declarations

Pretty-printer

6 declarations
classclass Ppr a where
#

Methods

Instances35Ppr, …
  • Ppr TypeArgDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr BangDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr ClauseDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr ConDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr DecDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr DecidedStrictnessDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr ExpDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr FamilyResultSigDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr ForeignDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr FunDepDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr InfoDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr InjectivityAnnDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr InlineDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr LitDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr LocDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr MatchDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr ModuleDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr ModuleInfoDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr NameDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr PatDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr PatSynArgsDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr PatSynDirDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr PhasesDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr PragmaDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr RangeDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr RoleDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr RuleBndrDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr RuleMatchDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr SourceStrictnessDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr SourceUnpackednessDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr StmtDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr TyLitDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr TypeDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • Ppr a => Ppr [a]Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr
  • PprFlag flag => Ppr (TyVarBndr flag)Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.Ppr