Safe Haskell | None |
---|
Desugars full Template Haskell syntax into a smaller core syntax for further processing. The desugared types and constructors are prefixed with a D.
- data DExp
- data DLetDec
- data DPat
- data DType
- data DKind
- type DCxt = [DPred]
- data DPred
- data DTyVarBndr
- data DMatch = DMatch DPat DExp
- data DClause = DClause [DPat] DExp
- dsExp :: Exp -> Q DExp
- dsPat :: Pat -> Q (DPat, DExp -> DExp)
- dsPats :: [Pat] -> Q ([DPat], DExp -> DExp)
- dsLetDec :: Dec -> Q DLetDec
- dsType :: Type -> Q DType
- dsKind :: Kind -> Q DKind
- dsTvb :: TyVarBndr -> Q DTyVarBndr
- dsPred :: Pred -> Q DPred
- dsMatches :: Name -> [Match] -> Q [DMatch]
- dsBody :: Body -> [Dec] -> DExp -> Q DExp
- dsGuards :: [(Guard, Exp)] -> DExp -> Q DExp
- dsDoStmts :: [Stmt] -> Q DExp
- dsComp :: [Stmt] -> Q DExp
- dsClauses :: Name -> [Clause] -> Q [DClause]
- dPatToDExp :: DPat -> DExp
- removeWilds :: DPat -> Q DPat
- reifyWithWarning :: Name -> Q Info
- getDataD :: String -> Name -> Q ([TyVarBndr], [Con])
- dataConNameToCon :: Name -> Q Con
- mkTupleDExp :: [DExp] -> DExp
- mkTupleDPat :: [DPat] -> DPat
- extractBoundNamesStmt :: Stmt -> Set Name
- extractBoundNamesDec :: Dec -> Set Name
- extractBoundNamesPat :: Pat -> Set Name
Desugared data types
Corresponds to TH's Exp
type. Note that DLamE
takes names, not patterns.
Declarations as used in a let
statement. Other Dec
s are not desugared.
Corresponds to TH's Pat
type.
Corresponds to TH's Type
type.
Corresponds to TH's Kind
type, which is a synonym for Type
. DKind
, though,
only contains constructors that make sense for kinds.
data DTyVarBndr Source
Corresponds to TH's TyVarBndr
. Note that PlainTV x
and KindedTV x StarT
are
distinct, so we retain that distinction here.
Main desugaring functions
dsPat :: Pat -> Q (DPat, DExp -> DExp)Source
Desugar a pattern, returning the desugared pattern and a transformation to be applied to the scope of the pattern match
dsPats :: [Pat] -> Q ([DPat], DExp -> DExp)Source
Desugar a list of patterns, producing a list of desugared patterns and one
transformation (like dsPat
)
dsTvb :: TyVarBndr -> Q DTyVarBndrSource
Desugar a TyVarBndr
Secondary desugaring functions
:: Name | Name of the scrutinee, which must be a bare var |
-> [Match] | Matches of the |
-> Q [DMatch] |
Desugar a list of matches for a case
statement
:: Body | body to desugar |
-> [Dec] | where declarations |
-> DExp | what to do if the guards don't match |
-> Q DExp |
Desugar a Body
Desugar guarded expressions
Desugar clauses to a function definition
Utility functions
removeWilds :: DPat -> Q DPatSource
Remove all wildcards from a pattern, replacing any wildcard with a fresh variable
reifyWithWarning :: Name -> Q InfoSource
Reify a declaration, warning the user about splices if the reify fails. The warning says that reification can fail if you try to reify a type in the same splice as it is declared.
:: String | Print this out on failure |
-> Name | Name of the datatype ( |
-> Q ([TyVarBndr], [Con]) |
Extract the TyVarBndr
s and constructors given the Name
of a type
dataConNameToCon :: Name -> Q ConSource
From the name of a data constructor, retrieve its definition as a Con
Extracting bound names
extractBoundNamesStmt :: Stmt -> Set NameSource
Extract the names bound in a Stmt
extractBoundNamesDec :: Dec -> Set NameSource
Extract the names bound in a Dec
that could appear in a let
expression.
extractBoundNamesPat :: Pat -> Set NameSource
Extract the names bound in a Pat