module Language.Haskell.TH.Lib (
InfoQ, ExpQ, TExpQ, DecQ, DecsQ, ConQ, TypeQ, KindQ, TyVarBndrQ,
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,
intPrimL, wordPrimL, floatPrimL, doublePrimL, integerL, rationalL,
charL, stringL, stringPrimL, charPrimL,
litP, varP, tupP, unboxedTupP, unboxedSumP, conP, uInfixP, parensP,
infixP, tildeP, bangP, asP, wildP, recP,
listP, sigP, viewP,
fieldPat,
normalB, guardedB, normalG, normalGE, patG, patGE, match, clause,
dyn, varE, unboundVarE, labelE, implicitParamVarE, conE, litE, staticE,
appE, appTypeE, uInfixE, parensE, infixE, infixApp, sectionL, sectionR,
lamE, lam1E, lamCaseE, tupE, unboxedTupE, unboxedSumE, condE, multiIfE,
letE, caseE, appsE, listE, sigE, recConE, recUpdE, stringE, fieldExp,
fromE, fromThenE, fromToE, fromThenToE,
arithSeqE,
fromR, fromThenR, fromToR, fromThenToR,
doE, mdoE, compE,
bindS, letS, noBindS, parS, recS,
forallT, varT, conT, appT, appKindT, arrowT, infixT, uInfixT, parensT,
equalityT, listT, tupleT, unboxedTupleT, unboxedSumT, sigT, litT,
wildCardT, promotedT, promotedTupleT, promotedNilT, promotedConsT,
implicitParamT,
numTyLit, strTyLit,
noSourceUnpackedness, sourceNoUnpack, sourceUnpack,
noSourceStrictness, sourceLazy, sourceStrict,
isStrict, notStrict, unpacked,
bang, bangType, varBangType, strictType, varStrictType,
cxt, classP, equalP,
normalC, recC, infixC, forallC, gadtC, recGadtC,
varK, conK, tupleK, arrowK, listK, appK, starK, constraintK,
plainTV, kindedTV,
nominalR, representationalR, phantomR, inferR,
valD, funD, tySynD, dataD, newtypeD,
derivClause, DerivClause(..),
stockStrategy, anyclassStrategy, newtypeStrategy,
viaStrategy, DerivStrategy(..),
classD, instanceD, instanceWithOverlapD, Overlap(..),
sigD, standaloneDerivD, standaloneDerivWithStrategyD, defaultSigD,
roleAnnotD,
dataFamilyD, openTypeFamilyD, closedTypeFamilyD, dataInstD,
newtypeInstD, tySynInstD,
tySynEqn, injectivityAnn, noSig, kindSig, tyVarSig,
infixLD, infixRD, infixND,
cCall, stdCall, cApi, prim, javaScript,
unsafe, safe, interruptible, forImpD,
funDep,
ruleVar, typedRuleVar,
valueAnnotation, typeAnnotation, moduleAnnotation,
pragInlD, pragSpecD, pragSpecInlD, pragSpecInstD, pragRuleD, pragAnnD,
pragLineD, pragCompleteD,
patSynD, patSynSigD, unidir, implBidir, explBidir, prefixPatSyn,
infixPatSyn, recordPatSyn,
implicitParamBindD,
thisModule
) where
import Language.Haskell.TH.Lib.Internal hiding
( tySynD
, dataD
, newtypeD
, classD
, pragRuleD
, dataInstD
, newtypeInstD
, dataFamilyD
, openTypeFamilyD
, closedTypeFamilyD
, tySynEqn
, forallC
, forallT
, sigT
, plainTV
, kindedTV
, starK
, constraintK
, noSig
, kindSig
, tyVarSig
, derivClause
, standaloneDerivWithStrategyD
, Role
, InjectivityAnn
)
import Language.Haskell.TH.Syntax
import Control.Monad (liftM2)
import Prelude
tySynD :: Name -> [TyVarBndr] -> TypeQ -> DecQ
tySynD :: Name -> [TyVarBndr] -> TypeQ -> DecQ
tySynD tc :: Name
tc tvs :: [TyVarBndr]
tvs rhs :: TypeQ
rhs = do { Type
rhs1 <- TypeQ
rhs; Dec -> DecQ
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> [TyVarBndr] -> Type -> Dec
TySynD Name
tc [TyVarBndr]
tvs Type
rhs1) }
dataD :: CxtQ -> Name -> [TyVarBndr] -> Maybe Kind -> [ConQ] -> [DerivClauseQ]
-> DecQ
dataD :: CxtQ
-> Name
-> [TyVarBndr]
-> Maybe Type
-> [ConQ]
-> [DerivClauseQ]
-> DecQ
dataD ctxt :: CxtQ
ctxt tc :: Name
tc tvs :: [TyVarBndr]
tvs ksig :: Maybe Type
ksig cons :: [ConQ]
cons derivs :: [DerivClauseQ]
derivs =
do
Cxt
ctxt1 <- CxtQ
ctxt
[Con]
cons1 <- [ConQ] -> Q [Con]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [ConQ]
cons
[DerivClause]
derivs1 <- [DerivClauseQ] -> Q [DerivClause]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [DerivClauseQ]
derivs
Dec -> DecQ
forall (m :: * -> *) a. Monad m => a -> m a
return (Cxt
-> Name
-> [TyVarBndr]
-> Maybe Type
-> [Con]
-> [DerivClause]
-> Dec
DataD Cxt
ctxt1 Name
tc [TyVarBndr]
tvs Maybe Type
ksig [Con]
cons1 [DerivClause]
derivs1)
newtypeD :: CxtQ -> Name -> [TyVarBndr] -> Maybe Kind -> ConQ -> [DerivClauseQ]
-> DecQ
newtypeD :: CxtQ
-> Name
-> [TyVarBndr]
-> Maybe Type
-> ConQ
-> [DerivClauseQ]
-> DecQ
newtypeD ctxt :: CxtQ
ctxt tc :: Name
tc tvs :: [TyVarBndr]
tvs ksig :: Maybe Type
ksig con :: ConQ
con derivs :: [DerivClauseQ]
derivs =
do
Cxt
ctxt1 <- CxtQ
ctxt
Con
con1 <- ConQ
con
[DerivClause]
derivs1 <- [DerivClauseQ] -> Q [DerivClause]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [DerivClauseQ]
derivs
Dec -> DecQ
forall (m :: * -> *) a. Monad m => a -> m a
return (Cxt
-> Name -> [TyVarBndr] -> Maybe Type -> Con -> [DerivClause] -> Dec
NewtypeD Cxt
ctxt1 Name
tc [TyVarBndr]
tvs Maybe Type
ksig Con
con1 [DerivClause]
derivs1)
classD :: CxtQ -> Name -> [TyVarBndr] -> [FunDep] -> [DecQ] -> DecQ
classD :: CxtQ -> Name -> [TyVarBndr] -> [FunDep] -> [DecQ] -> DecQ
classD ctxt :: CxtQ
ctxt cls :: Name
cls tvs :: [TyVarBndr]
tvs fds :: [FunDep]
fds decs :: [DecQ]
decs =
do
[Dec]
decs1 <- [DecQ] -> Q [Dec]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [DecQ]
decs
Cxt
ctxt1 <- CxtQ
ctxt
Dec -> DecQ
forall (m :: * -> *) a. Monad m => a -> m a
return (Dec -> DecQ) -> Dec -> DecQ
forall a b. (a -> b) -> a -> b
$ Cxt -> Name -> [TyVarBndr] -> [FunDep] -> [Dec] -> Dec
ClassD Cxt
ctxt1 Name
cls [TyVarBndr]
tvs [FunDep]
fds [Dec]
decs1
pragRuleD :: String -> [RuleBndrQ] -> ExpQ -> ExpQ -> Phases -> DecQ
pragRuleD :: String -> [RuleBndrQ] -> ExpQ -> ExpQ -> Phases -> DecQ
pragRuleD n :: String
n bndrs :: [RuleBndrQ]
bndrs lhs :: ExpQ
lhs rhs :: ExpQ
rhs phases :: Phases
phases
= do
[RuleBndr]
bndrs1 <- [RuleBndrQ] -> Q [RuleBndr]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [RuleBndrQ]
bndrs
Exp
lhs1 <- ExpQ
lhs
Exp
rhs1 <- ExpQ
rhs
Dec -> DecQ
forall (m :: * -> *) a. Monad m => a -> m a
return (Dec -> DecQ) -> Dec -> DecQ
forall a b. (a -> b) -> a -> b
$ Pragma -> Dec
PragmaD (Pragma -> Dec) -> Pragma -> Dec
forall a b. (a -> b) -> a -> b
$ String
-> Maybe [TyVarBndr]
-> [RuleBndr]
-> Exp
-> Exp
-> Phases
-> Pragma
RuleP String
n Maybe [TyVarBndr]
forall a. Maybe a
Nothing [RuleBndr]
bndrs1 Exp
lhs1 Exp
rhs1 Phases
phases
dataInstD :: CxtQ -> Name -> [TypeQ] -> Maybe Kind -> [ConQ] -> [DerivClauseQ]
-> DecQ
dataInstD :: CxtQ
-> Name
-> [TypeQ]
-> Maybe Type
-> [ConQ]
-> [DerivClauseQ]
-> DecQ
dataInstD ctxt :: CxtQ
ctxt tc :: Name
tc tys :: [TypeQ]
tys ksig :: Maybe Type
ksig cons :: [ConQ]
cons derivs :: [DerivClauseQ]
derivs =
do
Cxt
ctxt1 <- CxtQ
ctxt
Type
ty1 <- (TypeQ -> TypeQ -> TypeQ) -> TypeQ -> [TypeQ] -> TypeQ
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl TypeQ -> TypeQ -> TypeQ
appT (Name -> TypeQ
conT Name
tc) [TypeQ]
tys
[Con]
cons1 <- [ConQ] -> Q [Con]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [ConQ]
cons
[DerivClause]
derivs1 <- [DerivClauseQ] -> Q [DerivClause]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [DerivClauseQ]
derivs
Dec -> DecQ
forall (m :: * -> *) a. Monad m => a -> m a
return (Cxt
-> Maybe [TyVarBndr]
-> Type
-> Maybe Type
-> [Con]
-> [DerivClause]
-> Dec
DataInstD Cxt
ctxt1 Maybe [TyVarBndr]
forall a. Maybe a
Nothing Type
ty1 Maybe Type
ksig [Con]
cons1 [DerivClause]
derivs1)
newtypeInstD :: CxtQ -> Name -> [TypeQ] -> Maybe Kind -> ConQ -> [DerivClauseQ]
-> DecQ
newtypeInstD :: CxtQ
-> Name -> [TypeQ] -> Maybe Type -> ConQ -> [DerivClauseQ] -> DecQ
newtypeInstD ctxt :: CxtQ
ctxt tc :: Name
tc tys :: [TypeQ]
tys ksig :: Maybe Type
ksig con :: ConQ
con derivs :: [DerivClauseQ]
derivs =
do
Cxt
ctxt1 <- CxtQ
ctxt
Type
ty1 <- (TypeQ -> TypeQ -> TypeQ) -> TypeQ -> [TypeQ] -> TypeQ
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl TypeQ -> TypeQ -> TypeQ
appT (Name -> TypeQ
conT Name
tc) [TypeQ]
tys
Con
con1 <- ConQ
con
[DerivClause]
derivs1 <- [DerivClauseQ] -> Q [DerivClause]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [DerivClauseQ]
derivs
Dec -> DecQ
forall (m :: * -> *) a. Monad m => a -> m a
return (Cxt
-> Maybe [TyVarBndr]
-> Type
-> Maybe Type
-> Con
-> [DerivClause]
-> Dec
NewtypeInstD Cxt
ctxt1 Maybe [TyVarBndr]
forall a. Maybe a
Nothing Type
ty1 Maybe Type
ksig Con
con1 [DerivClause]
derivs1)
dataFamilyD :: Name -> [TyVarBndr] -> Maybe Kind -> DecQ
dataFamilyD :: Name -> [TyVarBndr] -> Maybe Type -> DecQ
dataFamilyD tc :: Name
tc tvs :: [TyVarBndr]
tvs kind :: Maybe Type
kind
= Dec -> DecQ
forall (m :: * -> *) a. Monad m => a -> m a
return (Dec -> DecQ) -> Dec -> DecQ
forall a b. (a -> b) -> a -> b
$ Name -> [TyVarBndr] -> Maybe Type -> Dec
DataFamilyD Name
tc [TyVarBndr]
tvs Maybe Type
kind
openTypeFamilyD :: Name -> [TyVarBndr] -> FamilyResultSig
-> Maybe InjectivityAnn -> DecQ
openTypeFamilyD :: Name
-> [TyVarBndr] -> FamilyResultSig -> Maybe InjectivityAnn -> DecQ
openTypeFamilyD tc :: Name
tc tvs :: [TyVarBndr]
tvs res :: FamilyResultSig
res inj :: Maybe InjectivityAnn
inj
= Dec -> DecQ
forall (m :: * -> *) a. Monad m => a -> m a
return (Dec -> DecQ) -> Dec -> DecQ
forall a b. (a -> b) -> a -> b
$ TypeFamilyHead -> Dec
OpenTypeFamilyD (Name
-> [TyVarBndr]
-> FamilyResultSig
-> Maybe InjectivityAnn
-> TypeFamilyHead
TypeFamilyHead Name
tc [TyVarBndr]
tvs FamilyResultSig
res Maybe InjectivityAnn
inj)
closedTypeFamilyD :: Name -> [TyVarBndr] -> FamilyResultSig
-> Maybe InjectivityAnn -> [TySynEqnQ] -> DecQ
closedTypeFamilyD :: Name
-> [TyVarBndr]
-> FamilyResultSig
-> Maybe InjectivityAnn
-> [TySynEqnQ]
-> DecQ
closedTypeFamilyD tc :: Name
tc tvs :: [TyVarBndr]
tvs result :: FamilyResultSig
result injectivity :: Maybe InjectivityAnn
injectivity eqns :: [TySynEqnQ]
eqns =
do [TySynEqn]
eqns1 <- [TySynEqnQ] -> Q [TySynEqn]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [TySynEqnQ]
eqns
Dec -> DecQ
forall (m :: * -> *) a. Monad m => a -> m a
return (TypeFamilyHead -> [TySynEqn] -> Dec
ClosedTypeFamilyD (Name
-> [TyVarBndr]
-> FamilyResultSig
-> Maybe InjectivityAnn
-> TypeFamilyHead
TypeFamilyHead Name
tc [TyVarBndr]
tvs FamilyResultSig
result Maybe InjectivityAnn
injectivity) [TySynEqn]
eqns1)
tySynEqn :: (Maybe [TyVarBndr]) -> TypeQ -> TypeQ -> TySynEqnQ
tySynEqn :: Maybe [TyVarBndr] -> TypeQ -> TypeQ -> TySynEqnQ
tySynEqn tvs :: Maybe [TyVarBndr]
tvs lhs :: TypeQ
lhs rhs :: TypeQ
rhs =
do
Type
lhs1 <- TypeQ
lhs
Type
rhs1 <- TypeQ
rhs
TySynEqn -> TySynEqnQ
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe [TyVarBndr] -> Type -> Type -> TySynEqn
TySynEqn Maybe [TyVarBndr]
tvs Type
lhs1 Type
rhs1)
forallC :: [TyVarBndr] -> CxtQ -> ConQ -> ConQ
forallC :: [TyVarBndr] -> CxtQ -> ConQ -> ConQ
forallC ns :: [TyVarBndr]
ns ctxt :: CxtQ
ctxt con :: ConQ
con = (Cxt -> Con -> Con) -> CxtQ -> ConQ -> ConQ
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 ([TyVarBndr] -> Cxt -> Con -> Con
ForallC [TyVarBndr]
ns) CxtQ
ctxt ConQ
con
forallT :: [TyVarBndr] -> CxtQ -> TypeQ -> TypeQ
forallT :: [TyVarBndr] -> CxtQ -> TypeQ -> TypeQ
forallT tvars :: [TyVarBndr]
tvars ctxt :: CxtQ
ctxt ty :: TypeQ
ty = do
Cxt
ctxt1 <- CxtQ
ctxt
Type
ty1 <- TypeQ
ty
Type -> TypeQ
forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> TypeQ) -> Type -> TypeQ
forall a b. (a -> b) -> a -> b
$ [TyVarBndr] -> Cxt -> Type -> Type
ForallT [TyVarBndr]
tvars Cxt
ctxt1 Type
ty1
sigT :: TypeQ -> Kind -> TypeQ
sigT :: TypeQ -> Type -> TypeQ
sigT t :: TypeQ
t k :: Type
k
= do
Type
t' <- TypeQ
t
Type -> TypeQ
forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> TypeQ) -> Type -> TypeQ
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
SigT Type
t' Type
k
plainTV :: Name -> TyVarBndr
plainTV :: Name -> TyVarBndr
plainTV = Name -> TyVarBndr
PlainTV
kindedTV :: Name -> Kind -> TyVarBndr
kindedTV :: Name -> Type -> TyVarBndr
kindedTV = Name -> Type -> TyVarBndr
KindedTV
starK :: Kind
starK :: Type
starK = Type
StarT
constraintK :: Kind
constraintK :: Type
constraintK = Type
ConstraintT
noSig :: FamilyResultSig
noSig :: FamilyResultSig
noSig = FamilyResultSig
NoSig
kindSig :: Kind -> FamilyResultSig
kindSig :: Type -> FamilyResultSig
kindSig = Type -> FamilyResultSig
KindSig
tyVarSig :: TyVarBndr -> FamilyResultSig
tyVarSig :: TyVarBndr -> FamilyResultSig
tyVarSig = TyVarBndr -> FamilyResultSig
TyVarSig
derivClause :: Maybe DerivStrategy -> [PredQ] -> DerivClauseQ
derivClause :: Maybe DerivStrategy -> [TypeQ] -> DerivClauseQ
derivClause mds :: Maybe DerivStrategy
mds p :: [TypeQ]
p = do
Cxt
p' <- [TypeQ] -> CxtQ
cxt [TypeQ]
p
DerivClause -> DerivClauseQ
forall (m :: * -> *) a. Monad m => a -> m a
return (DerivClause -> DerivClauseQ) -> DerivClause -> DerivClauseQ
forall a b. (a -> b) -> a -> b
$ Maybe DerivStrategy -> Cxt -> DerivClause
DerivClause Maybe DerivStrategy
mds Cxt
p'
standaloneDerivWithStrategyD :: Maybe DerivStrategy -> CxtQ -> TypeQ -> DecQ
standaloneDerivWithStrategyD :: Maybe DerivStrategy -> CxtQ -> TypeQ -> DecQ
standaloneDerivWithStrategyD mds :: Maybe DerivStrategy
mds ctxt :: CxtQ
ctxt ty :: TypeQ
ty = do
Cxt
ctxt' <- CxtQ
ctxt
Type
ty' <- TypeQ
ty
Dec -> DecQ
forall (m :: * -> *) a. Monad m => a -> m a
return (Dec -> DecQ) -> Dec -> DecQ
forall a b. (a -> b) -> a -> b
$ Maybe DerivStrategy -> Cxt -> Type -> Dec
StandaloneDerivD Maybe DerivStrategy
mds Cxt
ctxt' Type
ty'