Portability | non-portable |
---|---|
Stability | experimental |
Maintainer | Richard Eisenberg (eir@cis.upenn.edu) |
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
- data DDec
- = DLetDec DLetDec
- | DDataD NewOrData DCxt Name [DTyVarBndr] [DCon] [Name]
- | DTySynD Name [DTyVarBndr] DType
- | DClassD DCxt Name [DTyVarBndr] [FunDep] [DDec]
- | DInstanceD DCxt DType [DDec]
- | DForeignD DForeign
- | DPragmaD DPragma
- | DFamilyD FamFlavour Name [DTyVarBndr] (Maybe DKind)
- | DDataInstD NewOrData DCxt Name [DType] [DCon] [Name]
- | DTySynInstD Name DTySynEqn
- | DClosedTypeFamilyD Name [DTyVarBndr] (Maybe DKind) [DTySynEqn]
- | DRoleAnnotD Name [Role]
- data NewOrData
- data DCon = DCon [DTyVarBndr] DCxt Name DConFields
- data DConFields
- = DNormalC [DStrictType]
- | DRecC [DVarStrictType]
- type DStrictType = (Strict, DType)
- type DVarStrictType = (Name, Strict, DType)
- data DForeign
- data DPragma
- data DRuleBndr
- data DTySynEqn = DTySynEqn [DType] DType
- data DInfo
- type DInstanceDec = DDec
- data Role
- = NominalR
- | RepresentationalR
- | PhantomR
- | InferR
- data AnnTarget
- class Desugar th ds | ds -> th where
- dsExp :: Quasi q => Exp -> q DExp
- dsDecs :: Quasi q => [Dec] -> q [DDec]
- dsType :: Quasi q => Type -> q DType
- dsKind :: Quasi q => Kind -> q DKind
- dsInfo :: Quasi q => Info -> q DInfo
- dsPatOverExp :: Quasi q => Pat -> DExp -> q (DPat, DExp)
- dsPatsOverExp :: Quasi q => [Pat] -> DExp -> q ([DPat], DExp)
- dsPatX :: Quasi q => Pat -> q (DPat, [(Name, DExp)])
- dsLetDecs :: Quasi q => [Dec] -> q [DLetDec]
- dsTvb :: Quasi q => TyVarBndr -> q DTyVarBndr
- dsCxt :: Quasi q => Cxt -> q DCxt
- dsCon :: Quasi q => Con -> q DCon
- dsForeign :: Quasi q => Foreign -> q DForeign
- dsPragma :: Quasi q => Pragma -> q DPragma
- dsRuleBndr :: Quasi q => RuleBndr -> q DRuleBndr
- type PatM q = WriterT [(Name, DExp)] q
- dsPred :: Quasi q => Pred -> q DCxt
- dsPat :: Quasi q => Pat -> PatM q DPat
- dsDec :: Quasi q => Dec -> q [DDec]
- dsLetDec :: Quasi q => Dec -> q [DLetDec]
- dsMatches :: Quasi q => Name -> [Match] -> q [DMatch]
- dsBody :: Quasi q => Body -> [Dec] -> DExp -> q DExp
- dsGuards :: Quasi q => [(Guard, Exp)] -> DExp -> q DExp
- dsDoStmts :: Quasi q => [Stmt] -> q DExp
- dsComp :: Quasi q => [Stmt] -> q DExp
- dsClauses :: Quasi q => Name -> [Clause] -> q [DClause]
- applyDExp :: DExp -> [DExp] -> DExp
- applyDType :: DType -> [DType] -> DType
- dPatToDExp :: DPat -> DExp
- removeWilds :: Quasi q => DPat -> q DPat
- reifyWithWarning :: Quasi q => Name -> q Info
- getDataD :: Quasi q => String -> Name -> q ([TyVarBndr], [Con])
- dataConNameToDataName :: Quasi q => Name -> q Name
- dataConNameToCon :: Quasi q => Name -> q Con
- nameOccursIn :: Data a => Name -> a -> Bool
- allNamesIn :: Data a => a -> [Name]
- flattenDValD :: Quasi q => DLetDec -> q [DLetDec]
- getRecordSelectors :: Quasi q => DType -> DCon -> q [DLetDec]
- mkTypeName :: Quasi q => String -> q Name
- mkDataName :: Quasi q => String -> q Name
- newUniqueName :: Quasi q => String -> q Name
- mkTupleDExp :: [DExp] -> DExp
- mkTupleDPat :: [DPat] -> DPat
- maybeDLetE :: [DLetDec] -> DExp -> DExp
- maybeDCaseE :: String -> DExp -> [DMatch] -> DExp
- 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.
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.
Corresponds to TH's Pred
data DTyVarBndr Source
Corresponds to TH's TyVarBndr
. Note that PlainTV x
and KindedTV x StarT
are
distinct, so we retain that distinction here.
Corresponds to TH's Match
type.
Corresponds to TH's Clause
type.
Corresponds to TH's Dec
type.
Is it a newtype
or a data
type?
Corresponds to TH's Con
type.
data DConFields Source
A list of fields either for a standard data constructor or a record data constructor.
type DStrictType = (Strict, DType)Source
Corresponds to TH's StrictType
type.
type DVarStrictType = (Name, Strict, DType)Source
Corresponds to TH's VarStrictType
type.
Corresponds to TH's Foreign
type.
Corresponds to TH's Pragma
type.
Corresponds to TH's RuleBndr
type.
Corresponds to TH's TySynEqn
type (to store type family equations).
Corresponds to TH's Info
type.
DTyConI DDec (Maybe [DInstanceDec]) | |
DVarI Name DType (Maybe Name) Fixity | The |
DTyVarI Name DKind | |
DPrimTyConI Name Int Bool | The |
type DInstanceDecSource
= DDec | Guaranteed to be an instance declaration |
Same as Role
from TH; defined here for GHC 7.6.3 compatibility.
Same as AnnTarget
from TH; defined here for GHC 7.6.3 compatibility.
The Desugar
class
Main desugaring functions
dsPatOverExp :: Quasi q => Pat -> DExp -> q (DPat, DExp)Source
Desugar a pattern, along with processing a (desugared) expression that is the entire scope of the variables bound in the pattern.
dsPatsOverExp :: Quasi q => [Pat] -> DExp -> q ([DPat], DExp)Source
Desugar multiple patterns. Like dsPatOverExp
.
dsPatX :: Quasi q => Pat -> q (DPat, [(Name, DExp)])Source
Desugar a pattern, returning a list of (Name, DExp) pairs of extra variables that must be bound within the scope of the pattern
dsTvb :: Quasi q => TyVarBndr -> q DTyVarBndrSource
Desugar a TyVarBndr
dsRuleBndr :: Quasi q => RuleBndr -> q DRuleBndrSource
Desugar a RuleBndr
.
Secondary desugaring functions
type PatM q = WriterT [(Name, DExp)] qSource
Desugaring a pattern also returns the list of variables bound in as-patterns and the values they should be bound to. This variables must be brought into scope in the body of the pattern.
dsLetDec :: Quasi q => Dec -> q [DLetDec]Source
Desugar a single Dec
, perhaps producing multiple DLetDec
s
:: Quasi q | |
=> 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
:: Quasi q | |
=> Body | body to desugar |
-> [Dec] | where declarations |
-> DExp | what to do if the guards don't match |
-> q DExp |
Desugar a Body
:: Quasi q | |
=> [(Guard, Exp)] | Guarded expressions |
-> DExp | What to do if none of the guards match |
-> q DExp |
Desugar guarded expressions
Desugar clauses to a function definition
Utility functions
removeWilds :: Quasi q => DPat -> q DPatSource
Remove all wildcards from a pattern, replacing any wildcard with a fresh variable
reifyWithWarning :: Quasi q => 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.
:: Quasi q | |
=> 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
dataConNameToDataName :: Quasi q => Name -> q NameSource
From the name of a data constructor, retrive the datatype definition it is a part of.
dataConNameToCon :: Quasi q => Name -> q ConSource
From the name of a data constructor, retrieve its definition as a Con
nameOccursIn :: Data a => Name -> a -> BoolSource
Check if a name occurs anywhere within a TH tree.
allNamesIn :: Data a => a -> [Name]Source
Extract all Names mentioned in a TH tree.
flattenDValD :: Quasi q => DLetDec -> q [DLetDec]Source
If the declaration passed in is a DValD
, creates new, equivalent
declarations such that the DPat
in all DValD
s is just a plain
DVarPa
. Other declarations are passed through unchanged.
Note that the declarations that come out of this function are rather
less efficient than those that come in: they have many more pattern
matches.
mkTypeName :: Quasi q => String -> q NameSource
Like TH's lookupTypeName
, but if this name is not bound, then we assume
it is declared in the current module.
mkDataName :: Quasi q => String -> q NameSource
Like TH's lookupDataName
, but if this name is not bound, then we assume
it is declared in the current module.
newUniqueName :: Quasi q => String -> q NameSource
Like newName, but even more unique (unique across different splices),
and with unique nameBase
s.
maybeDLetE :: [DLetDec] -> DExp -> DExpSource
If decs is non-empty, delcare them in a let:
maybeDCaseE :: String -> DExp -> [DMatch] -> DExpSource
If matches is non-empty, make a case statement; otherwise make an error statement
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