{-# 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.

module Language.Haskell.TH.Lib (
    -- All of the exports from this module should
    -- be "public" functions.  The main module TH
    -- re-exports them all.

    -- * Library functions
    -- ** Abbreviations
        InfoQ, 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,

    -- ** Constructors lifted to 'Q'
    -- *** Literals
        intPrimL, wordPrimL, floatPrimL, doublePrimL, integerL, rationalL,
        charL, stringL, stringPrimL, charPrimL, bytesPrimL, mkBytes,
    -- *** Patterns
        litP, varP, tupP, unboxedTupP, unboxedSumP, conP, uInfixP, parensP,
        infixP, tildeP, bangP, asP, wildP, recP,
        listP, sigP, viewP,
        fieldPat,

    -- *** Pattern Guards
        normalB, guardedB, normalG, normalGE, patG, patGE, match, clause,

    -- *** Expressions
        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,
        getFieldE, projectionE,
    -- **** Ranges
    fromE, fromThenE, fromToE, fromThenToE,

    -- ***** Ranges with more indirection
    arithSeqE,
    fromR, fromThenR, fromToR, fromThenToR,
    -- **** Statements
    doE, mdoE, compE,
    bindS, letS, noBindS, parS, recS,

    -- *** Types
        forallT, forallVisT, varT, conT, appT, appKindT, arrowT, infixT,
        mulArrowT,
        uInfixT, parensT, equalityT, listT, tupleT, unboxedTupleT, unboxedSumT,
        sigT, litT, wildCardT, promotedT, promotedTupleT, promotedNilT,
        promotedConsT, implicitParamT,
    -- **** Type literals
    numTyLit, strTyLit, charTyLit,
    -- **** Strictness
    noSourceUnpackedness, sourceNoUnpack, sourceUnpack,
    noSourceStrictness, sourceLazy, sourceStrict,
    isStrict, notStrict, unpacked,
    bang, bangType, varBangType, strictType, varStrictType,
    -- **** Class Contexts
    cxt, classP, equalP,
    -- **** Constructors
    normalC, recC, infixC, forallC, gadtC, recGadtC,

    -- *** Kinds
    varK, conK, tupleK, arrowK, listK, appK, starK, constraintK,

    -- *** Type variable binders
    plainTV, kindedTV,
    plainInvisTV, kindedInvisTV,
    specifiedSpec, inferredSpec,

    -- *** Roles
    nominalR, representationalR, phantomR, inferR,

    -- *** Top Level Declarations
    -- **** Data
    valD, funD, tySynD, dataD, newtypeD,
    derivClause, DerivClause(..),
    stockStrategy, anyclassStrategy, newtypeStrategy,
    viaStrategy, DerivStrategy(..),
    -- **** Class
    classD, instanceD, instanceWithOverlapD, Overlap(..),
    sigD, kiSigD, standaloneDerivD, standaloneDerivWithStrategyD, defaultSigD,

    -- **** Role annotations
    roleAnnotD,
    -- **** Type Family / Data Family
    dataFamilyD, openTypeFamilyD, closedTypeFamilyD, dataInstD,
    newtypeInstD, tySynInstD,
    tySynEqn, injectivityAnn, noSig, kindSig, tyVarSig,

    -- **** Fixity
    infixLD, infixRD, infixND,

    -- **** Foreign Function Interface (FFI)
    cCall, stdCall, cApi, prim, javaScript,
    unsafe, safe, interruptible, forImpD,

    -- **** Functional dependencies
    funDep,

    -- **** Pragmas
    ruleVar, typedRuleVar,
    valueAnnotation, typeAnnotation, moduleAnnotation,
    pragInlD, pragSpecD, pragSpecInlD, pragSpecInstD, pragRuleD, pragAnnD,
    pragLineD, pragCompleteD,

    -- **** Pattern Synonyms
    patSynD, patSynSigD, unidir, implBidir, explBidir, prefixPatSyn,
    infixPatSyn, recordPatSyn,

    -- **** Implicit Parameters
    implicitParamBindD,

    -- ** Reify
    thisModule,

    -- ** Documentation
    withDecDoc, withDecsDoc, funD_doc, dataD_doc, newtypeD_doc, dataInstD_doc,
    newtypeInstD_doc, patSynD_doc

   ) 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

  , doE
  , mdoE
  , tupE
  , unboxedTupE

  , conP

  , Role
  , InjectivityAnn
  )
import qualified Language.Haskell.TH.Lib.Internal as Internal
import Language.Haskell.TH.Syntax

import Control.Applicative ( liftA2 )
import Foreign.ForeignPtr
import Data.Word
import Prelude

-- 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.)

-------------------------------------------------------------------------------
-- *   Dec

tySynD :: Quote m => Name -> [TyVarBndr ()] -> m Type -> m Dec
tySynD :: forall (m :: * -> *).
Quote m =>
Name -> [TyVarBndr ()] -> m Type -> m Dec
tySynD Name
tc [TyVarBndr ()]
tvs m Type
rhs = do { Type
rhs1 <- m Type
rhs; Dec -> m Dec
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> [TyVarBndr ()] -> Type -> Dec
TySynD Name
tc [TyVarBndr ()]
tvs Type
rhs1) }

dataD :: Quote m => m Cxt -> Name -> [TyVarBndr ()] -> Maybe Kind -> [m Con] -> [m DerivClause]
      -> m Dec
dataD :: forall (m :: * -> *).
Quote m =>
m Cxt
-> Name
-> [TyVarBndr ()]
-> Maybe Type
-> [m Con]
-> [m DerivClause]
-> m Dec
dataD m Cxt
ctxt Name
tc [TyVarBndr ()]
tvs Maybe Type
ksig [m Con]
cons [m DerivClause]
derivs =
  do
    Cxt
ctxt1 <- m Cxt
ctxt
    [Con]
cons1 <- [m Con] -> m [Con]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [m Con]
cons
    [DerivClause]
derivs1 <- [m DerivClause] -> m [DerivClause]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [m DerivClause]
derivs
    Dec -> m Dec
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 :: Quote m => m Cxt -> Name -> [TyVarBndr ()] -> Maybe Kind -> m Con -> [m DerivClause]
         -> m Dec
newtypeD :: forall (m :: * -> *).
Quote m =>
m Cxt
-> Name
-> [TyVarBndr ()]
-> Maybe Type
-> m Con
-> [m DerivClause]
-> m Dec
newtypeD m Cxt
ctxt Name
tc [TyVarBndr ()]
tvs Maybe Type
ksig m Con
con [m DerivClause]
derivs =
  do
    Cxt
ctxt1 <- m Cxt
ctxt
    Con
con1 <- m Con
con
    [DerivClause]
derivs1 <- [m DerivClause] -> m [DerivClause]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [m DerivClause]
derivs
    Dec -> m Dec
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 :: Quote m => m Cxt -> Name -> [TyVarBndr ()] -> [FunDep] -> [m Dec] -> m Dec
classD :: forall (m :: * -> *).
Quote m =>
m Cxt -> Name -> [TyVarBndr ()] -> [FunDep] -> [m Dec] -> m Dec
classD m Cxt
ctxt Name
cls [TyVarBndr ()]
tvs [FunDep]
fds [m Dec]
decs =
  do
    [Dec]
decs1 <- [m Dec] -> m [Dec]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [m Dec]
decs
    Cxt
ctxt1 <- m Cxt
ctxt
    Dec -> m Dec
forall (m :: * -> *) a. Monad m => a -> m a
return (Dec -> m Dec) -> Dec -> m Dec
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 :: Quote m => String -> [m RuleBndr] -> m Exp -> m Exp -> Phases -> m Dec
pragRuleD :: 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
  = do
      [RuleBndr]
bndrs1 <- [m RuleBndr] -> m [RuleBndr]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [m RuleBndr]
bndrs
      Exp
lhs1   <- m Exp
lhs
      Exp
rhs1   <- m Exp
rhs
      Dec -> m Dec
forall (m :: * -> *) a. Monad m => a -> m a
return (Dec -> m Dec) -> Dec -> m Dec
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 :: Quote m => m Cxt -> Name -> [m Type] -> Maybe Kind -> [m Con] -> [m DerivClause]
          -> m Dec
dataInstD :: 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 =
  do
    Cxt
ctxt1 <- m Cxt
ctxt
    Type
ty1 <- (m Type -> m Type -> m Type) -> m Type -> [m Type] -> m Type
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl m Type -> m Type -> m Type
forall (m :: * -> *). Quote m => m Type -> m Type -> m Type
appT (Name -> m Type
forall (m :: * -> *). Quote m => Name -> m Type
conT Name
tc) [m Type]
tys
    [Con]
cons1 <- [m Con] -> m [Con]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [m Con]
cons
    [DerivClause]
derivs1 <- [m DerivClause] -> m [DerivClause]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [m DerivClause]
derivs
    Dec -> m Dec
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 :: Quote m => m Cxt -> Name -> [m Type] -> Maybe Kind -> m Con -> [m DerivClause]
             -> m Dec
newtypeInstD :: 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 =
  do
    Cxt
ctxt1 <- m Cxt
ctxt
    Type
ty1 <- (m Type -> m Type -> m Type) -> m Type -> [m Type] -> m Type
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl m Type -> m Type -> m Type
forall (m :: * -> *). Quote m => m Type -> m Type -> m Type
appT (Name -> m Type
forall (m :: * -> *). Quote m => Name -> m Type
conT Name
tc) [m Type]
tys
    Con
con1  <- m Con
con
    [DerivClause]
derivs1 <- [m DerivClause] -> m [DerivClause]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [m DerivClause]
derivs
    Dec -> m Dec
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 :: Quote m => Name -> [TyVarBndr ()] -> Maybe Kind -> m Dec
dataFamilyD :: forall (m :: * -> *).
Quote m =>
Name -> [TyVarBndr ()] -> Maybe Type -> m Dec
dataFamilyD Name
tc [TyVarBndr ()]
tvs Maybe Type
kind
    = Dec -> m Dec
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Dec -> m Dec) -> Dec -> m Dec
forall a b. (a -> b) -> a -> b
$ Name -> [TyVarBndr ()] -> Maybe Type -> Dec
DataFamilyD Name
tc [TyVarBndr ()]
tvs Maybe Type
kind

openTypeFamilyD :: Quote m => Name -> [TyVarBndr ()] -> FamilyResultSig
                -> Maybe InjectivityAnn -> m Dec
openTypeFamilyD :: forall (m :: * -> *).
Quote m =>
Name
-> [TyVarBndr ()]
-> FamilyResultSig
-> Maybe InjectivityAnn
-> m Dec
openTypeFamilyD Name
tc [TyVarBndr ()]
tvs FamilyResultSig
res Maybe InjectivityAnn
inj
    = Dec -> m Dec
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 ()]
-> FamilyResultSig
-> Maybe InjectivityAnn
-> TypeFamilyHead
TypeFamilyHead Name
tc [TyVarBndr ()]
tvs FamilyResultSig
res Maybe InjectivityAnn
inj)

closedTypeFamilyD :: Quote m => Name -> [TyVarBndr ()] -> FamilyResultSig
                  -> Maybe InjectivityAnn -> [m TySynEqn] -> m Dec
closedTypeFamilyD :: forall (m :: * -> *).
Quote m =>
Name
-> [TyVarBndr ()]
-> FamilyResultSig
-> Maybe InjectivityAnn
-> [m TySynEqn]
-> m Dec
closedTypeFamilyD Name
tc [TyVarBndr ()]
tvs FamilyResultSig
result Maybe InjectivityAnn
injectivity [m TySynEqn]
eqns =
  do [TySynEqn]
eqns1 <- [m TySynEqn] -> m [TySynEqn]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [m TySynEqn]
eqns
     Dec -> m Dec
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 :: Quote m => (Maybe [TyVarBndr ()]) -> m Type -> m Type -> m TySynEqn
tySynEqn :: forall (m :: * -> *).
Quote m =>
Maybe [TyVarBndr ()] -> m Type -> m Type -> m TySynEqn
tySynEqn Maybe [TyVarBndr ()]
tvs m Type
lhs m Type
rhs =
  do
    Type
lhs1 <- m Type
lhs
    Type
rhs1 <- m Type
rhs
    TySynEqn -> m TySynEqn
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe [TyVarBndr ()] -> Type -> Type -> TySynEqn
TySynEqn Maybe [TyVarBndr ()]
tvs Type
lhs1 Type
rhs1)

forallC :: Quote m => [TyVarBndr Specificity] -> m Cxt -> m Con -> m Con
forallC :: 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 (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

-------------------------------------------------------------------------------
-- *   Type

forallT :: Quote m => [TyVarBndr Specificity] -> m Cxt -> m Type -> m Type
forallT :: forall (m :: * -> *).
Quote m =>
[TyVarBndr Specificity] -> m Cxt -> m Type -> m Type
forallT [TyVarBndr Specificity]
tvars m Cxt
ctxt m Type
ty = do
    Cxt
ctxt1 <- m Cxt
ctxt
    Type
ty1   <- m Type
ty
    Type -> m Type
forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> m Type) -> Type -> m Type
forall a b. (a -> b) -> a -> b
$ [TyVarBndr Specificity] -> Cxt -> Type -> Type
ForallT [TyVarBndr Specificity]
tvars Cxt
ctxt1 Type
ty1

sigT :: Quote m => m Type -> Kind -> m Type
sigT :: forall (m :: * -> *). Quote m => m Type -> Type -> m Type
sigT m Type
t Type
k
  = do
      Type
t' <- m Type
t
      Type -> m Type
forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> m Type) -> Type -> m Type
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
SigT Type
t' Type
k

-------------------------------------------------------------------------------
-- *   Kind

plainTV :: Name -> TyVarBndr ()
plainTV :: Name -> TyVarBndr ()
plainTV Name
n = Name -> () -> TyVarBndr ()
forall flag. Name -> flag -> TyVarBndr flag
PlainTV Name
n ()

kindedTV :: Name -> Kind -> TyVarBndr ()
kindedTV :: Name -> Type -> TyVarBndr ()
kindedTV Name
n Type
k = Name -> () -> Type -> TyVarBndr ()
forall flag. Name -> flag -> Type -> TyVarBndr flag
KindedTV Name
n () Type
k

starK :: Kind
starK :: Type
starK = Type
StarT

constraintK :: Kind
constraintK :: Type
constraintK = Type
ConstraintT

-------------------------------------------------------------------------------
-- *   Type family result

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

-------------------------------------------------------------------------------
-- * Top Level Declarations

derivClause :: Quote m => Maybe DerivStrategy -> [m Pred] -> m DerivClause
derivClause :: forall (m :: * -> *).
Quote m =>
Maybe DerivStrategy -> [m Type] -> m DerivClause
derivClause Maybe DerivStrategy
mds [m Type]
p = do
  Cxt
p' <- [m Type] -> m Cxt
forall (m :: * -> *). Quote m => [m Type] -> m Cxt
cxt [m Type]
p
  DerivClause -> m DerivClause
forall (m :: * -> *) a. Monad m => a -> m a
return (DerivClause -> m DerivClause) -> DerivClause -> m DerivClause
forall a b. (a -> b) -> a -> b
$ Maybe DerivStrategy -> Cxt -> DerivClause
DerivClause Maybe DerivStrategy
mds Cxt
p'

standaloneDerivWithStrategyD :: Quote m => Maybe DerivStrategy -> m Cxt -> m Type -> m Dec
standaloneDerivWithStrategyD :: forall (m :: * -> *).
Quote m =>
Maybe DerivStrategy -> m Cxt -> m Type -> m Dec
standaloneDerivWithStrategyD Maybe DerivStrategy
mds m Cxt
ctxt m Type
ty = do
  Cxt
ctxt' <- m Cxt
ctxt
  Type
ty'   <- m Type
ty
  Dec -> m Dec
forall (m :: * -> *) a. Monad m => a -> m a
return (Dec -> m Dec) -> Dec -> m Dec
forall a b. (a -> b) -> a -> b
$ Maybe DerivStrategy -> Cxt -> Type -> Dec
StandaloneDerivD Maybe DerivStrategy
mds Cxt
ctxt' Type
ty'

-------------------------------------------------------------------------------
-- * Bytes literals

-- | Create a Bytes datatype representing raw bytes to be embedded into the
-- program/library binary.
--
-- @since 2.16.0.0
mkBytes
   :: ForeignPtr Word8 -- ^ Pointer to the data
   -> Word             -- ^ Offset from the pointer
   -> Word             -- ^ Number of bytes
   -> Bytes
mkBytes :: ForeignPtr Word8 -> Word -> Word -> Bytes
mkBytes = ForeignPtr Word8 -> Word -> Word -> Bytes
Bytes

-------------------------------------------------------------------------------
-- * Tuple expressions

tupE :: Quote m => [m Exp] -> m Exp
tupE :: forall (m :: * -> *). Quote m => [m Exp] -> m Exp
tupE [m Exp]
es = do { [Exp]
es1 <- [m Exp] -> m [Exp]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [m Exp]
es; Exp -> m Exp
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 :: Quote m => [m Exp] -> m Exp
unboxedTupE :: forall (m :: * -> *). Quote m => [m Exp] -> m Exp
unboxedTupE [m Exp]
es = do { [Exp]
es1 <- [m Exp] -> m [Exp]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [m Exp]
es; Exp -> m Exp
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)}

-------------------------------------------------------------------------------
-- * Do expressions

doE :: Quote m => [m Stmt] -> m Exp
doE :: 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.doE Maybe ModName
forall a. Maybe a
Nothing

mdoE :: Quote m => [m Stmt] -> m Exp
mdoE :: 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.mdoE Maybe ModName
forall a. Maybe a
Nothing

-------------------------------------------------------------------------------
-- * Patterns

conP :: Quote m => Name -> [m Pat] -> m Pat
conP :: 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.conP Name
n [] [m Pat]
xs