template-haskell
Support library for Template Haskell
| LTS Haskell 24.17: | 2.22.0.0 | 
| Stackage Nightly 2025-10-31: | 2.23.0.0 | 
| Latest on Hackage: | 2.23.0.0 | 
template-haskell-2.23.0.0@sha256:15a0162484c76233568448de290bcb554f38ff5b2718f2dcd4a1ae8fa296ed22,1895Module documentation for 2.23.0.0
This package provides modules containing facilities for manipulating Haskell source code using Template Haskell.
See http://www.haskell.org/haskellwiki/Template_Haskell for more information.
Changes
Changelog for template-haskell package
2.23.0.0
- Extend ExpwithForallE,ForallVisE,ConstraintedE, introduce functionsforallE,forallVisE,constraintedE(GHC Proposal #281).
- template-haskellis no longer wired-in. All wired-in identifiers have been moved to- ghc-internal.
- Liftinstances were added for the- template-haskellAST.
2.22.0.0
- 
The kind of Codewas changed fromforall r. (Type -> Type) -> TYPE r -> Typeto(Type -> Type) -> forall r. TYPE r -> Type. This enables higher-kinded usage.
- 
Extend PatwithTypePandExpwithTypeE, introduce functionstypePandtypeE(GHC Proposal #281).
- 
Extend PragmawithSCCP.
- 
Extend PatwithInvisP, introduce functioninvisP. (Ghc Proposal #448).
- 
Add a new data type NamespaceSpecifierto representtype/datanamespace specifiers, which can be used in conjunction with theExplicitNamespacesextension:- 
The InfixDconstructor of theDecdata type now stores aNamespaceSpecifier.
- 
Add infixLWithSpecD,infixRWithSpecDandinfixNWithSpecDfunctions, which accept aNamespaceSpecifieras an argument.
 
- 
2.21.0.0
- 
Record fields now belong to separate NameSpaces, keyed by the parent of the record field. This is the name of the first constructor of the parent type, even if this constructor does not have the field in question.This change enables TemplateHaskell support for DuplicateRecordFields.
- 
Add support for generating typed splices and brackets in untyped Template Haskell Introduces typedSpliceE :: Quote m => m Exp -> m ExpandtypedBracketE :: Quote m => m Exp -> m Exp
- 
Add BndrVisto support invisible binders in type declarations (GHC Proposal #425).
- 
The binder flag type in plainTVandkindedTVis generalized from()to any data type with aDefaultBndrFlaginstance, including(),Specificity, andBndrVis.
2.20.0.0
- 
The Ppr.pprInfixTfunction has gained aPrecedenceargument.
- 
The values of named precedence levels like Ppr.appPrechave changed.
- 
Add TypeDataDconstructor to theDectype fortype datadeclarations (GHC proposal #106).
- 
Add instance Lift (Fixed a)
2.19.0.0
- 
Add DefaultDconstructor to support Haskelldefaultdeclarations.
- 
Add support for Overloaded Record Dot. Introduces getFieldE :: Quote m => m Exp -> String -> m ExpandprojectionE :: Quote m => [String] -> m Exp.
- 
Add instance Lift ByteArray.
- 
Add PromotedInfixTandPromotedUInfixT, which are analogs toInfixTandUInfixTthat ensure that if a dynamically bound name (i.e. a name withNameFlavourNameSorNameQ; the flavours produced bymkName) is used as operator, it will be bound to a promoted data constructor rather than a type constructor, if both are in scope.
- 
Add a vendor-filepathCabal flag to thetemplate-haskellpackage. If this flag is set thentemplate-haskellwill not depend on thefilepathpackage and will instead use some modules fromfilepaththat have been copied into thetemplate-haskellsource tree.
2.18.0.0
- 
The types of ConPandconPhave been changed to allow for an additional list of type applications preceding the argument patterns.
- 
Add support for the Charkind (#11342): we extend theTyLitdata type with the constructorCharTyLitthat reflects type-level characters.
- 
Add putDocandgetDocwhich allow Haddock documentation to be attached to module headers, declarations, function arguments and instances, as well as queried. These are quite low level operations, so for convenience there are several combinators that can be used withDecs directly, includingwithDecDoc/withDecsDocas well as_doccounterparts to many of theDechelper functions.
- 
Add newDeclarationGroupto document the effect of visibility while reifying types and instances.
2.17.0.0
- 
Typed Quotations now return a value of type Code m a(GHC Proposal #195). The main motiviation is to make writing instances easier and make it easier to storeCodevalues in type-indexed maps.
- 
Implement Overloaded Quotations (GHC Proposal #246). This patch modifies a few fundamental things in the API. All the library combinators are generalised to be in terms of a new minimal class Quote. The types oflift,liftTyped, andliftDataare modified to returnm Exprather thanQ Exp. Instances written in terms ofQare now disallowed. The types ofunsafeTExpCoerceandunTypeQare also generalised in terms ofQuoterather than specific toQ.
- 
Implement Explicit specificity in type variable binders (GHC Proposal #99). In Language.Haskell.TH.Syntax,TyVarBndris now annotated with aflag, denoting the additional argument to its constructorsPlainTVandKindedTV.flagis either theSpecificityof the type variable (SpecifiedSpecorInferredSpec) or().
- 
Fix Eq/Ord instances for Bytes: we were comparing pointers while we should compare the actual bytes (#16457).
- 
Fix Show instance for Bytes: we were showing the pointer value while we want to show the contents (#16457).
- 
Add SemigroupandMonoidinstances forQ(#18123).
- 
Add MonadFixinstance forQ(#12073).
- 
Add support for QualifiedDo. The data constructors DoEandMDoEgot a newMaybe ModNameargument to describe the qualifier of do blocks.
- 
The argument to TExpQcan now be levity polymorphic.
2.16.0.0 Jan 2020
- 
Bundled with GHC 8.10.1 
- 
Add support for tuple sections. (#15843) The type signatures of TupEandUnboxedTupEhave changed from[Exp] -> Expto[Maybe Exp] -> Exp. The type signatures oftupEandunboxedTupEremain the same for backwards compatibility.
- 
Introduce a liftTypedmethod to theLiftclass and set the default implementations ofliftin terms ofliftTyped.
- 
Add a ForallVisTconstructor toTypeto represent visible, dependent quantification.
- 
Introduce support for Bytesliterals (raw bytes embedded into the output binary)
- 
Make the Lifttypeclass levity-polymorphic and add instances for unboxed tuples, unboxed sums,Int#,Word#,Addr#,Float#, andDouble#.
- 
Introduce reifyTypeto reify the type or kind of a thing referenced byName.
2.15.0.0 May 2019
- 
Bundled with GHC 8.8.1 
- 
In Language.Haskell.TH.Syntax,DataInstD,NewTypeInstD,TySynEqn, andRulePnow all have aMaybe [TyVarBndr]argument, which contains a list of quantified type variables if an explicitforallis present, andNothingotherwise.DataInstD,NewTypeInstD,TySynEqnalso now use a singleTypeargument to represent the left-hand-side to avoid malformed type family equations and allow visible kind application.Correspondingly, in Language.Haskell.TH.Lib.Internal,pragRuleD,dataInstD,newtypeInstD, andtySynEqnnow all have aMaybe [TyVarBndrQ]argument. Non-API-breaking versions of these functions can be found inLanguage.Haskell.TH.Lib. The type signature oftySynEqnhas also changed from[TypeQ] -> TypeQ -> TySynEqnQto(Maybe [TyVarBndrQ]) -> TypeQ -> TypeQ -> TySynEqnQ, for the same reason as inLanguage.Haskell.TH.Syntaxabove. Consequently,tySynInstDalso changes fromName -> TySynEqnQ -> DecQtoTySynEqnQ -> DecQ.
- 
Add Liftinstances forNonEmptyandVoid
- 
addForeignFilePathnow support assembler sources (#16180).
2.14.0.0 September 2018
- 
Bundled with GHC 8.6.1 
- 
Introduce an addForeignFilePathfunction, as well as a correspondingqAddForeignFileclass method toQuasi. UnlikeaddForeignFile, which takes the contents of the file as an argument,addForeignFilePathtakes as an argument a path pointing to a foreign file. A newaddForeignSourcefunction has also been added which takes a file’s contents as an argument.The old addForeignFilefunction is now deprecated in favor ofaddForeignSource, and theqAddForeignFilemethod ofQuasihas been removed entirely.
- 
Introduce an addTempFilefunction, as well as a correspondingqAddTempFilemethod toQuasi, which requests a temporary file of a given suffix.
- 
Add a ViaStrategyconstructor toDerivStrategy.
- 
Add support for -XImplicitParamsviaImplicitParamT,ImplicitParamVarE, andImplicitParamBindD.
- 
Add support for -XRecursiveDoviaMDoEandRecS.
2.13.0.0 March 2018
- 
Bundled with GHC 8.4.1 
- 
Language.Haskell.TH.FamFlavour, which was deprecated in 2.11, has been removed.
- 
Add support for overloaded labels. Introduces labelE :: String -> ExpQ.
- 
Add KindQ,TyVarBndrQ, andFamilyResultSigQaliases toLanguage.Haskell.TH.Lib.
- 
Add Language.Haskell.TH.Lib.Internalmodule, which exposes some additional functionality that is used internally in GHC’s integration with Template Haskell. This is not a part of the public API, and as such, there are no API guarantees for this module from version to version.
- 
MonadIOis now a superclass ofQuasi,qRunIOhas a default implementationqRunIO = liftIO
- 
Add MonadIO Qinstance
2.12.0.0 July 2017
- 
Bundled with GHC 8.2.1 
- 
Add support for pattern synonyms. This introduces one new constructor to Info(PatSynI), two new constructors toDec(PatSynDandPatSynSigD), and two new data types (PatSynDirandPatSynArgs), among other changes. (#8761)
- 
Add support for unboxed sums. (#12478) 
- 
Add support for visible type applications. (#12530) 
- 
Add support for attaching deriving strategies to derivingstatements (#10598)
- 
Add support for COMPLETEpragmas. (#13098)
- 
unboxedTupleTypeNameandunboxedTupleDataNamenow work for unboxed 0-tuples and 1-tuples (#12977)
- 
Language.Haskell.THnow reexports all ofLanguage.Haskell.TH.Lib. (#12992). This causesLanguage.Haskell.THto export more types and functions that it did before:- TExp,- BangQ, and- FieldExpQ
- unboxedTupP,- unboxedTupEand- unboundVarE
- infixLD,- infixRD, and- infixND
- unboxedTupleTand- wildCardT
- plainTVand- kindedTV
- interruptibleand- funDep
- valueAnnotation,- typeAnnotation, and- moduleAnnotation
 
- 
Add support for overloaded labels. 
2.11.0.0 May 2016
- 
Bundled with GHC 8.0.1 
- 
The compiler can now resolve infix operator fixities in types on its own. The UInfixTconstructor ofTypeis analoguous toUInfixEfor expressions and can contain a tree of infix type applications which will be reassociated according to the fixities of the operators. TheParensTconstructor can be used to explicitly group expressions.
- 
Add namePackageandnameSpace
- 
Make dataToQaanddataToExpQable to handleDatainstances whosetoConstrimplementation relies on a function instead of a data constructor (#10796)
- 
Add Showinstances forNameFlavourandNameSpace
- 
Remove FamilyDandFamFlavour. AddDataFamilyDandOpenTypeFamilyDas the representation of data families and open type families respectively. (#6018)
- 
Add TypeFamilyHeadfor common elements ofOpenTypeFamilyDandClosedTypeFamilyD(#10902)
- 
The Strictdatatype was split among different datatypes: three for writing the strictness information of data constructors’ fields as denoted in Haskell source code (SourceUnpackednessandSourceStrictness, as well asBang), and one for strictness information after a constructor is compiled (DecidedStrictness).Strict,StrictTypeandVarStrictTypehave been deprecated in favor ofBang,BangTypeandVarBangType. (#10697)
- 
Add reifyConStrictnessto query a data constructor’sDecidedStrictnessvalues for its fields (#10697)
- 
The ClassOpI,DataConI, andVarIconstructors no longer have aFixityfield. Instead, allFixityinformation for a givenNameis now determined through thereifyFixityfunction, which returnsJustthe fixity if there is an explicit fixity declaration for thatName, andNothingotherwise (#10704 and #11345)
- 
Add MonadFail Qinstance for GHC 8.0 and later (#11661)
- 
Add support for OVERLAP(S/PED/PING) pragmas on instances 
2.10.0.0 Mar 2015
- Bundled with GHC 7.10.1
- Remove build-dependency on containerspackage
- Make Preda type synonym ofType, and deprecateclassP/equalP(#7021)
- Add support for LINEpragma viaprageLineDandLineP
- Replace Int#with!IntinNameFlavourconstructors
- Derive Genericfor TH types (#9527)
- Add standaloneDerivD(#8100)
- Add support for generic default signatures via defaultSigD(#9064)
- Add Liftinstances for()andRational
- Derive new ShowandDatainstances forLoc
- Derive Eqinstances forLoc,Info, andModuleInfo
- Make calling conventions available in template haskell consistent with those from GHC (#9703)
- Add support for -XStaticValuesviastaticE
- Add Ordinstances to TH types
- Merge some instances from th-orphans(Pprinstances forLitandLocas well asLiftinstances for numeric types
- Put parens around (ty :: kind)when pretty-printing TH syntax
