{-# LANGUAGE Safe #-}
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, bytesPrimL, mkBytes,
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, forallVisT, 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, kiSigD, 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
, tupE
, unboxedTupE
, Role
, InjectivityAnn
)
import Language.Haskell.TH.Syntax
import Control.Monad (liftM2)
import Foreign.ForeignPtr
import Data.Word
import Prelude
tySynD :: Name -> [TyVarBndr] -> TypeQ -> DecQ
tySynD :: Name -> [TyVarBndr] -> TypeQ -> DecQ
tySynD Name
tc [TyVarBndr]
tvs 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 CxtQ
ctxt Name
tc [TyVarBndr]
tvs Maybe Type
ksig [ConQ]
cons [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 CxtQ
ctxt Name
tc [TyVarBndr]
tvs Maybe Type
ksig ConQ
con [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 CxtQ
ctxt Name
cls [TyVarBndr]
tvs [FunDep]
fds [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 String
n [RuleBndrQ]
bndrs ExpQ
lhs ExpQ
rhs 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 CxtQ
ctxt Name
tc [TypeQ]
tys Maybe Type
ksig [ConQ]
cons [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 CxtQ
ctxt Name
tc [TypeQ]
tys Maybe Type
ksig ConQ
con [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 Name
tc [TyVarBndr]
tvs 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 Name
tc [TyVarBndr]
tvs FamilyResultSig
res 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 Name
tc [TyVarBndr]
tvs FamilyResultSig
result Maybe InjectivityAnn
injectivity [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 Maybe [TyVarBndr]
tvs TypeQ
lhs 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 [TyVarBndr]
ns CxtQ
ctxt 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 [TyVarBndr]
tvars CxtQ
ctxt 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 TypeQ
t 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 Maybe DerivStrategy
mds [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 Maybe DerivStrategy
mds CxtQ
ctxt 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'
mkBytes
:: ForeignPtr Word8
-> Word
-> Word
-> Bytes
mkBytes :: ForeignPtr Word8 -> Word -> Word -> Bytes
mkBytes = ForeignPtr Word8 -> Word -> Word -> Bytes
Bytes
tupE :: [ExpQ] -> ExpQ
tupE :: [ExpQ] -> ExpQ
tupE [ExpQ]
es = do { [Exp]
es1 <- [ExpQ] -> Q [Exp]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [ExpQ]
es; Exp -> ExpQ
forall (m :: * -> *) a. Monad m => a -> m a
return ([Maybe Exp] -> Exp
TupE ([Maybe Exp] -> Exp) -> [Maybe Exp] -> Exp
forall a b. (a -> b) -> a -> b
$ (Exp -> Maybe Exp) -> [Exp] -> [Maybe Exp]
forall a b. (a -> b) -> [a] -> [b]
map Exp -> Maybe Exp
forall a. a -> Maybe a
Just [Exp]
es1)}
unboxedTupE :: [ExpQ] -> ExpQ
unboxedTupE :: [ExpQ] -> ExpQ
unboxedTupE [ExpQ]
es = do { [Exp]
es1 <- [ExpQ] -> Q [Exp]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [ExpQ]
es; Exp -> ExpQ
forall (m :: * -> *) a. Monad m => a -> m a
return ([Maybe Exp] -> Exp
UnboxedTupE ([Maybe Exp] -> Exp) -> [Maybe Exp] -> Exp
forall a b. (a -> b) -> a -> b
$ (Exp -> Maybe Exp) -> [Exp] -> [Maybe Exp]
forall a b. (a -> b) -> [a] -> [b]
map Exp -> Maybe Exp
forall a. a -> Maybe a
Just [Exp]
es1)}