Safe Haskell | None |
---|
This module describes stripped-down Template Haskell abstract syntax trees (ASTs) for a subset of Haskell.
Synopsis
- type Body = Exp
- data Lit
- data Pat
- data Match = Match Pat Body
- data Dec = ValD Name Body
- data Exp
- data BindS = BindS Name Exp
- doE :: [BindS] -> Exp -> Exp
- getVarNames :: Pat -> Set Name
- substMatch :: Name -> Exp -> Match -> Match
- substDec :: Name -> Exp -> Dec -> Dec
- substExp :: Name -> Exp -> Exp -> Exp
- mapSubstExp :: Map Name Exp -> Exp -> Exp
- litTHtoExpAST :: Lit -> LiftQ Exp
- litTHtoPatAST :: Lit -> LiftQ Pat
- normalizePatInExp :: [Pat] -> LiftQ ([Name], Map Name Exp)
- whereToLet :: Exp -> [(Pat, Exp)] -> LiftQ Exp
- clauseToMatch :: Clause -> LiftQ Match
- clausesToLambda :: [Clause] -> LiftQ Exp
- expTHtoAST :: Exp -> LiftQ Exp
- matchTHtoAST :: Match -> LiftQ Match
- bodyTHtoAST :: Body -> LiftQ Exp
- patTHtoAST :: Pat -> LiftQ Pat
- firstLevelDecTHtoAST :: Dec -> Maybe (LiftQ Dec)
- decTHtoAST :: Dec -> LiftQ (Pat, Exp)
- typReturnE :: LiftQ Type
- typMAppE :: LiftQ Type
- litASTtoTH :: Lit -> Lit
- patASTtoTH :: Pat -> Pat
- matchASTtoTH :: Match -> LiftQ Match
- decASTtoTH :: Dec -> LiftQ Dec
- expASTtoTH :: Exp -> LiftQ Exp
- liftIntegerL :: Exp
- liftRationalL :: Exp
- liftLitAST :: Lit -> LiftQ Exp
- liftPatAST :: Pat -> LiftQ Pat
- liftMatchAST :: Match -> LiftQ Match
- liftDecAST :: Dec -> LiftQ Dec
- liftFirstLevelDecAST :: Dec -> LiftQ Dec
- liftExpAST :: Exp -> LiftQ Exp
- makeDecTemplate :: Dec -> LiftQ Dec
- prettyPrintAST :: Q [Dec] -> IO ()
- prettyPrintLiftExpTH :: Q Exp -> IO ()
- prettyPrintLiftExpAST :: LiftQ Exp -> IO ()
- decToMonad :: String -> Q [Dec] -> Q [Dec]
- expToMonad :: String -> Q Exp -> Q Exp
Abstract syntax trees of a simplified language
There are no "guarded bodies". One net effect is to make the "where" construct equivalent to a simple "let".
Literals.
Patterns.
Match term construct.
First-level declaration.
Expression
VarE Name | Variable name. |
ConE Name | Constant name. |
LitE Lit | Literal. |
AppE Exp Exp | Application. |
LamE Name Exp | Lambda abstraction. |
TupE [Exp] | Tuple. |
CondE Exp Exp Exp | If-then-else. |
LetE [Dec] Exp | Let-construct. |
CaseE Exp [Match] | Case distinction |
ListE [Exp] | List: |
ReturnE | hardcoded constant for |
MAppE | hardcoded constant for |
Syntactic sugar to recover do-notation.
Variable substitution
Downgrading Template Haskell to AST
normalizePatInExp :: [Pat] -> LiftQ ([Name], Map Name Exp) Source #
Take a list of patterns coming from a where
section and output
a list of fresh names for normalized let
s. Also gives a mapping
for substituting inside the expressions. Assume all names in the
list of patterns are distinct.
clausesToLambda :: [Clause] -> LiftQ Exp Source #
From a list of TH clauses, make a case-distinction wrapped in a lambda abstraction.
decTHtoAST :: Dec -> LiftQ (Pat, Exp) Source #
Downgrade any declarations (including the ones in where
-constructs).
Upgrade AST to Template Haskell
litASTtoTH :: Lit -> Lit Source #
Upgrade literals
patASTtoTH :: Pat -> Pat Source #
Upgrade patterns.
Lifting AST terms (into AST terms)
liftIntegerL :: Exp Source #
Variable referring to the lifting function for integers.
liftRationalL :: Exp Source #
Variable referring to the lifting function for reals.
makeDecTemplate :: Dec -> LiftQ Dec Source #
make a declaration into a template-declaration (by renaming with the template-prefix).