{-# LANGUAGE Safe #-}-- |-- Language.Haskell.TH.Lib contains lots of useful helper functions for-- generating and manipulating Template Haskell terms-- Note: this module mostly re-exports functions from-- Language.Haskell.TH.Lib.Internal, but if a change occurs to Template-- Haskell which requires breaking the API offered in this module, we opt to-- copy the old definition here, and make the changes in-- Language.Haskell.TH.Lib.Internal. This way, we can retain backwards-- compatibility while still allowing GHC to make changes as it needs.moduleLanguage.Haskell.TH.Lib (-- All of the exports from this module should-- be "public" functions. The main module TH-- re-exports them all.-- * Library functions-- ** AbbreviationsInfoQ,ExpQ,TExpQ,CodeQ,DecQ,DecsQ,ConQ,TypeQ,KindQ,TyLitQ,CxtQ,PredQ,DerivClauseQ,MatchQ,ClauseQ,BodyQ,GuardQ,StmtQ,RangeQ,SourceStrictnessQ,SourceUnpackednessQ,BangQ,BangTypeQ,VarBangTypeQ,StrictTypeQ,VarStrictTypeQ,FieldExpQ,PatQ,FieldPatQ,RuleBndrQ,TySynEqnQ,PatSynDirQ,PatSynArgsQ,FamilyResultSigQ,DerivStrategyQ,TyVarBndrUnit,TyVarBndrSpec,TyVarBndrVis,-- ** Constructors lifted to 'Q'-- *** LiteralsintPrimL,wordPrimL,floatPrimL,doublePrimL,integerL,rationalL,charL,stringL,stringPrimL,charPrimL,bytesPrimL,mkBytes ,-- *** PatternslitP,varP,tupP,unboxedTupP,unboxedSumP,conP ,uInfixP,parensP,infixP,tildeP,bangP,asP,wildP,recP,listP,sigP,viewP,typeP,invisP,fieldPat,-- *** Pattern GuardsnormalB,guardedB,normalG,normalGE,patG,patGE,match,clause,-- *** Expressionsdyn,varE,unboundVarE,labelE,implicitParamVarE,conE,litE,staticE,appE,appTypeE,uInfixE,parensE,infixE,infixApp,sectionL,sectionR,lamE,lam1E,lamCaseE,lamCasesE,tupE ,unboxedTupE ,unboxedSumE,condE,multiIfE,letE,caseE,appsE,listE,sigE,recConE,recUpdE,stringE,fieldExp,getFieldE,projectionE,typedSpliceE,typedBracketE,typeE,forallE,forallVisE,constrainedE,-- **** RangesfromE,fromThenE,fromToE,fromThenToE,-- ***** Ranges with more indirectionarithSeqE,fromR,fromThenR,fromToR,fromThenToR,-- **** StatementsdoE ,mdoE ,compE,bindS,letS,noBindS,parS,recS,-- *** TypesforallT ,forallVisT,varT,conT,appT,appKindT,arrowT,mulArrowT,infixT,uInfixT,promotedInfixT,promotedUInfixT,parensT,equalityT,listT,tupleT,unboxedTupleT,unboxedSumT,sigT ,litT,wildCardT,promotedT,promotedTupleT,promotedNilT,promotedConsT,implicitParamT,-- **** Type literalsnumTyLit,strTyLit,charTyLit,-- **** StrictnessnoSourceUnpackedness,sourceNoUnpack,sourceUnpack,noSourceStrictness,sourceLazy,sourceStrict,isStrict,notStrict,unpacked,bang,bangType,varBangType,strictType,varStrictType,-- **** Class Contextscxt,classP,equalP,-- **** ConstructorsnormalC,recC,infixC,forallC ,gadtC,recGadtC,-- *** KindsvarK,conK,tupleK,arrowK,listK,appK,starK ,constraintK ,-- *** Type variable bindersDefaultBndrFlag (defaultBndrFlag ),plainTV ,kindedTV ,plainInvisTV,kindedInvisTV,plainBndrTV,kindedBndrTV,specifiedSpec,inferredSpec,bndrReq,bndrInvis,-- *** RolesnominalR,representationalR,phantomR,inferR,-- *** Top Level Declarations-- **** DatavalD,funD,tySynD ,dataD ,newtypeD ,typeDataD ,derivClause ,DerivClause(..),stockStrategy,anyclassStrategy,newtypeStrategy,viaStrategy,DerivStrategy(..),-- **** ClassclassD ,instanceD,instanceWithOverlapD,Overlap(..),sigD,kiSigD,standaloneDerivD,standaloneDerivWithStrategyD ,defaultSigD,-- **** Role annotationsroleAnnotD,-- **** Type Family / Data FamilydataFamilyD ,openTypeFamilyD ,closedTypeFamilyD ,dataInstD ,newtypeInstD ,tySynInstD,tySynEqn ,injectivityAnn,noSig ,kindSig ,tyVarSig ,-- **** FixityinfixLD,infixRD,infixND,-- **** Default declarationdefaultD,-- **** Foreign Function Interface (FFI)cCall,stdCall,cApi,prim,javaScript,unsafe,safe,interruptible,forImpD,-- **** Functional dependenciesfunDep,-- **** PragmasruleVar,typedRuleVar,valueAnnotation,typeAnnotation,moduleAnnotation,pragInlD,pragSpecD,pragSpecInlD,pragSpecInstD,pragRuleD ,pragAnnD,pragLineD,pragCompleteD,-- **** Pattern SynonymspatSynD,patSynSigD,unidir,implBidir,explBidir,prefixPatSyn,infixPatSyn,recordPatSyn,-- **** Implicit ParametersimplicitParamBindD,-- ** ReifythisModule,-- ** DocumentationwithDecDoc,withDecsDoc,funD_doc,dataD_doc,newtypeD_doc,typeDataD_doc,dataInstD_doc,newtypeInstD_doc,patSynD_doc)whereimportGHC.Internal.TH.Libhiding(tySynD,dataD,newtypeD,typeDataD,classD,pragRuleD,dataInstD,newtypeInstD,dataFamilyD,openTypeFamilyD,closedTypeFamilyD,tySynEqn,forallC,forallT,sigT,plainTV,kindedTV,starK,constraintK,noSig,kindSig,tyVarSig,derivClause,standaloneDerivWithStrategyD,doE,mdoE,tupE,unboxedTupE,conP,Role,InjectivityAnn)importqualifiedGHC.Internal.TH.LibasInternalimportLanguage.Haskell.TH.Syntax importControl.Applicative(Applicative(..))importForeign.ForeignPtrimportData.WordimportPreludehiding(Applicative(..))-- All definitions below represent the "old" API, since their definitions are-- different in Language.Haskell.TH.Lib.Internal. Please think carefully before-- deciding to change the APIs of the functions below, as they represent the-- public API (as opposed to the Internal module, which has no API promises.)--------------------------------------------------------------------------------- * DectySynD ::Quotem =>Name->[TyVarBndrBndrVis]->m Type->m DectySynD :: forall (m :: * -> *). Quote m => Name -> [TyVarBndr BndrVis] -> m Type -> m Dec tySynD Name tc [TyVarBndr BndrVis] tvs m Type rhs =do{rhs1 <-m Type rhs ;return(TySynDtc tvs rhs1 )}dataD ::Quotem =>m Cxt->Name->[TyVarBndrBndrVis]->MaybeKind->[m Con]->[m DerivClause]->m DecdataD :: forall (m :: * -> *). Quote m => m Cxt -> Name -> [TyVarBndr BndrVis] -> Maybe Type -> [m Con] -> [m DerivClause] -> m Dec dataD m Cxt ctxt Name tc [TyVarBndr BndrVis] tvs Maybe Type ksig [m Con] cons [m DerivClause] derivs =doctxt1 <-m Cxt ctxt cons1 <-sequenceAcons derivs1 <-sequenceAderivs return(DataDctxt1 tc tvs ksig cons1 derivs1 )newtypeD ::Quotem =>m Cxt->Name->[TyVarBndrBndrVis]->MaybeKind->m Con->[m DerivClause]->m DecnewtypeD :: forall (m :: * -> *). Quote m => m Cxt -> Name -> [TyVarBndr BndrVis] -> Maybe Type -> m Con -> [m DerivClause] -> m Dec newtypeD m Cxt ctxt Name tc [TyVarBndr BndrVis] tvs Maybe Type ksig m Con con [m DerivClause] derivs =doctxt1 <-m Cxt ctxt con1 <-con derivs1 <-sequenceAderivs return(NewtypeDctxt1 tc tvs ksig con1 derivs1 )typeDataD ::Quotem =>Name->[TyVarBndrBndrVis]->MaybeKind->[m Con]->m DectypeDataD :: forall (m :: * -> *). Quote m => Name -> [TyVarBndr BndrVis] -> Maybe Type -> [m Con] -> m Dec typeDataD Name tc [TyVarBndr BndrVis] tvs Maybe Type ksig [m Con] cons =docons1 <-[m Con] -> m [Con] forall (t :: * -> *) (f :: * -> *) a. (Traversable t, Applicative f) => t (f a) -> f (t a) forall (f :: * -> *) a. Applicative f => [f a] -> f [a] sequenceA[m Con] cons return(TypeDataDtc tvs ksig cons1 )classD ::Quotem =>m Cxt->Name->[TyVarBndrBndrVis]->[FunDep]->[m Dec]->m DecclassD :: forall (m :: * -> *). Quote m => m Cxt -> Name -> [TyVarBndr BndrVis] -> [FunDep] -> [m Dec] -> m Dec classD m Cxt ctxt Name cls [TyVarBndr BndrVis] tvs [FunDep] fds [m Dec] decs =dodecs1 <-[m Dec] -> m [Dec] forall (t :: * -> *) (f :: * -> *) a. (Traversable t, Applicative f) => t (f a) -> f (t a) forall (f :: * -> *) a. Applicative f => [f a] -> f [a] sequenceA[m Dec] decs ctxt1 <-ctxt return$ClassDctxt1 cls tvs fds decs1 pragRuleD ::Quotem =>String->[m RuleBndr]->m Exp->m Exp->Phases->m DecpragRuleD :: forall (m :: * -> *). Quote m => String -> [m RuleBndr] -> m Exp -> m Exp -> Phases -> m Dec pragRuleD String n [m RuleBndr] bndrs m Exp lhs m Exp rhs Phases phases =dobndrs1 <-[m RuleBndr] -> m [RuleBndr] forall (t :: * -> *) (f :: * -> *) a. (Traversable t, Applicative f) => t (f a) -> f (t a) forall (f :: * -> *) a. Applicative f => [f a] -> f [a] sequenceA[m RuleBndr] bndrs lhs1 <-lhs rhs1 <-rhs return$PragmaD$RulePn Nothingbndrs1 lhs1 rhs1 phases dataInstD ::Quotem =>m Cxt->Name->[m Type]->MaybeKind->[m Con]->[m DerivClause]->m DecdataInstD :: forall (m :: * -> *). Quote m => m Cxt -> Name -> [m Type] -> Maybe Type -> [m Con] -> [m DerivClause] -> m Dec dataInstD m Cxt ctxt Name tc [m Type] tys Maybe Type ksig [m Con] cons [m DerivClause] derivs =doctxt1 <-m Cxt ctxt ty1 <-foldlappT(conTtc )tys cons1 <-sequenceAcons derivs1 <-sequenceAderivs return(DataInstDctxt1 Nothingty1 ksig cons1 derivs1 )newtypeInstD ::Quotem =>m Cxt->Name->[m Type]->MaybeKind->m Con->[m DerivClause]->m DecnewtypeInstD :: forall (m :: * -> *). Quote m => m Cxt -> Name -> [m Type] -> Maybe Type -> m Con -> [m DerivClause] -> m Dec newtypeInstD m Cxt ctxt Name tc [m Type] tys Maybe Type ksig m Con con [m DerivClause] derivs =doctxt1 <-m Cxt ctxt ty1 <-foldlappT(conTtc )tys con1 <-con derivs1 <-sequenceAderivs return(NewtypeInstDctxt1 Nothingty1 ksig con1 derivs1 )dataFamilyD ::Quotem =>Name->[TyVarBndrBndrVis]->MaybeKind->m DecdataFamilyD :: forall (m :: * -> *). Quote m => Name -> [TyVarBndr BndrVis] -> Maybe Type -> m Dec dataFamilyD Name tc [TyVarBndr BndrVis] tvs Maybe Type kind =Dec -> m Dec forall a. a -> m a forall (f :: * -> *) a. Applicative f => a -> f a pure(Dec -> m Dec) -> Dec -> m Dec forall a b. (a -> b) -> a -> b $Name -> [TyVarBndr BndrVis] -> Maybe Type -> Dec DataFamilyDName tc [TyVarBndr BndrVis] tvs Maybe Type kind openTypeFamilyD ::Quotem =>Name->[TyVarBndrBndrVis]->FamilyResultSig->MaybeInjectivityAnn->m DecopenTypeFamilyD :: forall (m :: * -> *). Quote m => Name -> [TyVarBndr BndrVis] -> FamilyResultSig -> Maybe InjectivityAnn -> m Dec openTypeFamilyD Name tc [TyVarBndr BndrVis] tvs FamilyResultSig res Maybe InjectivityAnn inj =Dec -> m Dec forall a. a -> m a forall (f :: * -> *) a. Applicative f => a -> f a pure(Dec -> m Dec) -> Dec -> m Dec forall a b. (a -> b) -> a -> b $TypeFamilyHead -> Dec OpenTypeFamilyD(Name -> [TyVarBndr BndrVis] -> FamilyResultSig -> Maybe InjectivityAnn -> TypeFamilyHead TypeFamilyHeadName tc [TyVarBndr BndrVis] tvs FamilyResultSig res Maybe InjectivityAnn inj )closedTypeFamilyD ::Quotem =>Name->[TyVarBndrBndrVis]->FamilyResultSig->MaybeInjectivityAnn->[m TySynEqn]->m DecclosedTypeFamilyD :: forall (m :: * -> *). Quote m => Name -> [TyVarBndr BndrVis] -> FamilyResultSig -> Maybe InjectivityAnn -> [m TySynEqn] -> m Dec closedTypeFamilyD Name tc [TyVarBndr BndrVis] tvs FamilyResultSig result Maybe InjectivityAnn injectivity [m TySynEqn] eqns =doeqns1 <-[m TySynEqn] -> m [TySynEqn] forall (t :: * -> *) (f :: * -> *) a. (Traversable t, Applicative f) => t (f a) -> f (t a) forall (f :: * -> *) a. Applicative f => [f a] -> f [a] sequenceA[m TySynEqn] eqns return(ClosedTypeFamilyD(TypeFamilyHeadtc tvs result injectivity )eqns1 )tySynEqn ::Quotem =>(Maybe[TyVarBndr()])->m Type->m Type->m TySynEqntySynEqn :: forall (m :: * -> *). Quote m => Maybe [TyVarBndr ()] -> m Type -> m Type -> m TySynEqn tySynEqn Maybe [TyVarBndr ()] tvs m Type lhs m Type rhs =dolhs1 <-m Type lhs rhs1 <-rhs return(TySynEqntvs lhs1 rhs1 )forallC ::Quotem =>[TyVarBndrSpecificity]->m Cxt->m Con->m ConforallC :: forall (m :: * -> *). Quote m => [TyVarBndr Specificity] -> m Cxt -> m Con -> m Con forallC [TyVarBndr Specificity] ns m Cxt ctxt m Con con =(Cxt -> Con -> Con) -> m Cxt -> m Con -> m Con forall a b c. (a -> b -> c) -> m a -> m b -> m c forall (f :: * -> *) a b c. Applicative f => (a -> b -> c) -> f a -> f b -> f c liftA2([TyVarBndr Specificity] -> Cxt -> Con -> Con ForallC[TyVarBndr Specificity] ns )m Cxt ctxt m Con con --------------------------------------------------------------------------------- * TypeforallT ::Quotem =>[TyVarBndrSpecificity]->m Cxt->m Type->m TypeforallT :: forall (m :: * -> *). Quote m => [TyVarBndr Specificity] -> m Cxt -> m Type -> m Type forallT [TyVarBndr Specificity] tvars m Cxt ctxt m Type ty =doctxt1 <-m Cxt ctxt ty1 <-ty return$ForallTtvars ctxt1 ty1 sigT ::Quotem =>m Type->Kind->m TypesigT :: forall (m :: * -> *). Quote m => m Type -> Type -> m Type sigT m Type t Type k =dot' <-m Type t return$SigTt' k --------------------------------------------------------------------------------- * Type variable bindersclassDefaultBndrFlag flag wheredefaultBndrFlag ::flag instanceDefaultBndrFlag ()wheredefaultBndrFlag :: () defaultBndrFlag =()instanceDefaultBndrFlag SpecificitywheredefaultBndrFlag :: Specificity defaultBndrFlag =Specificity SpecifiedSpecinstanceDefaultBndrFlag BndrViswheredefaultBndrFlag :: BndrVis defaultBndrFlag =BndrVis BndrReqplainTV ::DefaultBndrFlag flag =>Name->TyVarBndrflag plainTV :: forall flag. DefaultBndrFlag flag => Name -> TyVarBndr flag plainTV Name n =Name -> flag -> TyVarBndr flag forall flag. Name -> flag -> TyVarBndr flag PlainTVName n flag forall flag. DefaultBndrFlag flag => flag defaultBndrFlag kindedTV ::DefaultBndrFlag flag =>Name->Kind->TyVarBndrflag kindedTV :: forall flag. DefaultBndrFlag flag => Name -> Type -> TyVarBndr flag kindedTV Name n Type k =Name -> flag -> Type -> TyVarBndr flag forall flag. Name -> flag -> Type -> TyVarBndr flag KindedTVName n flag forall flag. DefaultBndrFlag flag => flag defaultBndrFlag Type k --------------------------------------------------------------------------------- * KindstarK ::KindstarK :: Type starK =Type StarTconstraintK ::KindconstraintK :: Type constraintK =Type ConstraintT--------------------------------------------------------------------------------- * Type family resultnoSig ::FamilyResultSignoSig :: FamilyResultSig noSig =FamilyResultSig NoSigkindSig ::Kind->FamilyResultSigkindSig :: Type -> FamilyResultSig kindSig =Type -> FamilyResultSig KindSigtyVarSig ::TyVarBndr()->FamilyResultSigtyVarSig :: TyVarBndr () -> FamilyResultSig tyVarSig =TyVarBndr () -> FamilyResultSig TyVarSig--------------------------------------------------------------------------------- * Top Level DeclarationsderivClause ::Quotem =>MaybeDerivStrategy->[m Pred]->m DerivClausederivClause :: forall (m :: * -> *). Quote m => Maybe DerivStrategy -> [m Type] -> m DerivClause derivClause Maybe DerivStrategy mds [m Type] p =dop' <-[m Type] -> m Cxt forall (m :: * -> *). Quote m => [m Type] -> m Cxt cxt[m Type] p return$DerivClausemds p' standaloneDerivWithStrategyD ::Quotem =>MaybeDerivStrategy->m Cxt->m Type->m DecstandaloneDerivWithStrategyD :: forall (m :: * -> *). Quote m => Maybe DerivStrategy -> m Cxt -> m Type -> m Dec standaloneDerivWithStrategyD Maybe DerivStrategy mds m Cxt ctxt m Type ty =doctxt' <-m Cxt ctxt ty' <-ty return$StandaloneDerivDmds ctxt' ty' --------------------------------------------------------------------------------- * Bytes literals-- | Create a Bytes datatype representing raw bytes to be embedded into the-- program/library binary.---- @since 2.16.0.0mkBytes ::ForeignPtrWord8-- ^ Pointer to the data->Word-- ^ Offset from the pointer->Word-- ^ Number of bytes->BytesmkBytes :: ForeignPtr Word8 -> Word -> Word -> Bytes mkBytes =ForeignPtr Word8 -> Word -> Word -> Bytes Bytes--------------------------------------------------------------------------------- * Tuple expressionstupE ::Quotem =>[m Exp]->m ExptupE :: forall (m :: * -> *). Quote m => [m Exp] -> m Exp tupE [m Exp] es =do{es1 <-[m Exp] -> m [Exp] forall (t :: * -> *) (f :: * -> *) a. (Traversable t, Applicative f) => t (f a) -> f (t a) forall (f :: * -> *) a. Applicative f => [f a] -> f [a] sequenceA[m Exp] es ;return(TupE$mapJustes1 )}unboxedTupE ::Quotem =>[m Exp]->m ExpunboxedTupE :: forall (m :: * -> *). Quote m => [m Exp] -> m Exp unboxedTupE [m Exp] es =do{es1 <-[m Exp] -> m [Exp] forall (t :: * -> *) (f :: * -> *) a. (Traversable t, Applicative f) => t (f a) -> f (t a) forall (f :: * -> *) a. Applicative f => [f a] -> f [a] sequenceA[m Exp] es ;return(UnboxedTupE$mapJustes1 )}--------------------------------------------------------------------------------- * Do expressionsdoE ::Quotem =>[m Stmt]->m ExpdoE :: forall (m :: * -> *). Quote m => [m Stmt] -> m Exp doE =Maybe ModName -> [m Stmt] -> m Exp forall (m :: * -> *). Quote m => Maybe ModName -> [m Stmt] -> m Exp Internal.doEMaybe ModName forall a. Maybe a NothingmdoE ::Quotem =>[m Stmt]->m ExpmdoE :: forall (m :: * -> *). Quote m => [m Stmt] -> m Exp mdoE =Maybe ModName -> [m Stmt] -> m Exp forall (m :: * -> *). Quote m => Maybe ModName -> [m Stmt] -> m Exp Internal.mdoEMaybe ModName forall a. Maybe a Nothing--------------------------------------------------------------------------------- * PatternsconP ::Quotem =>Name->[m Pat]->m PatconP :: forall (m :: * -> *). Quote m => Name -> [m Pat] -> m Pat conP Name n [m Pat] xs =Name -> [m Type] -> [m Pat] -> m Pat forall (m :: * -> *). Quote m => Name -> [m Type] -> [m Pat] -> m Pat Internal.conPName n [][m Pat] xs