The Quipper System

Safe HaskellNone

Quipper.Utils.Template.Lifting

Contents

Description

This module describes stripped-down Template Haskell abstract syntax trees (ASTs) for a subset of Haskell.

Synopsis

Abstract syntax trees of a simplified language

type Body = Exp Source #

There are no "guarded bodies". One net effect is to make the "where" construct equivalent to a simple "let".

data Lit Source #

Literals.

Constructors

CharL Char

Characters.

IntegerL Integer

Integers.

RationalL Rational

Reals.

Instances
Show Lit # 
Instance details

Defined in Quipper.Utils.Template.Lifting

Methods

showsPrec :: Int -> Lit -> ShowS #

show :: Lit -> String #

showList :: [Lit] -> ShowS #

data Pat Source #

Patterns.

Constructors

LitP Lit

Literal.

VarP Name

Variable name.

TupP [Pat]

Tuple.

WildP

Wildchar.

ListP [Pat]

List as [...].

ConP Name [Pat]

Cons: h:t.

Instances
Show Pat # 
Instance details

Defined in Quipper.Utils.Template.Lifting

Methods

showsPrec :: Int -> Pat -> ShowS #

show :: Pat -> String #

showList :: [Pat] -> ShowS #

data Match Source #

Match term construct.

Constructors

Match Pat Body 
Instances
Show Match # 
Instance details

Defined in Quipper.Utils.Template.Lifting

Methods

showsPrec :: Int -> Match -> ShowS #

show :: Match -> String #

showList :: [Match] -> ShowS #

data Dec Source #

First-level declaration.

Constructors

ValD Name Body 
Instances
Show Dec # 
Instance details

Defined in Quipper.Utils.Template.Lifting

Methods

showsPrec :: Int -> Dec -> ShowS #

show :: Dec -> String #

showList :: [Dec] -> ShowS #

data Exp Source #

Expression

Constructors

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

MAppE

hardcoded constant for >>=.

Instances
Show Exp # 
Instance details

Defined in Quipper.Utils.Template.Lifting

Methods

showsPrec :: Int -> Exp -> ShowS #

show :: Exp -> String #

showList :: [Exp] -> ShowS #

Syntactic sugar to recover do-notation.

data BindS Source #

Datatype to encode the notation x <- expr.

Constructors

BindS Name Exp 

doE :: [BindS] -> Exp -> Exp Source #

A simple do: list of monadic let followed by a computation.

Variable substitution

getVarNames :: Pat -> Set Name Source #

Get the set of variable names in a pattern.

substMatch :: Name -> Exp -> Match -> Match Source #

Substitution in a Match.

substDec :: Name -> Exp -> Dec -> Dec Source #

Substitution in a Dec.

substExp :: Name -> Exp -> Exp -> Exp Source #

Substitution in an Exp.

mapSubstExp :: Map Name Exp -> Exp -> Exp Source #

Substitution of several variables in one go.

Downgrading Template Haskell to AST

litTHtoExpAST :: Lit -> LiftQ Exp Source #

Downgrading TH literals to Exp.

litTHtoPatAST :: Lit -> LiftQ Pat Source #

Downgrading TH literals to Pat.

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 lets. Also gives a mapping for substituting inside the expressions. Assume all names in the list of patterns are distinct.

whereToLet :: Exp -> [(Pat, Exp)] -> LiftQ Exp Source #

Build a let-expression out of pieces.

clauseToMatch :: Clause -> LiftQ Match Source #

Build a Match out of a TH clause

clausesToLambda :: [Clause] -> LiftQ Exp Source #

From a list of TH clauses, make a case-distinction wrapped in a lambda abstraction.

expTHtoAST :: Exp -> LiftQ Exp Source #

Downgrade expressions.

matchTHtoAST :: Match -> LiftQ Match Source #

Downgrade match-constructs.

bodyTHtoAST :: Body -> LiftQ Exp Source #

Downgrade bodies into expressions.

patTHtoAST :: Pat -> LiftQ Pat Source #

Downgrade patterns.

firstLevelDecTHtoAST :: Dec -> Maybe (LiftQ Dec) Source #

Downgrade first-level declarations.

decTHtoAST :: Dec -> LiftQ (Pat, Exp) Source #

Downgrade any declarations (including the ones in where-constructs).

Upgrade AST to Template Haskell

typReturnE :: LiftQ Type Source #

Abstract syntax tree of the type of the function return.

typMAppE :: LiftQ Type Source #

Abstract syntax tree of the type of the function >>=.

litASTtoTH :: Lit -> Lit Source #

Upgrade literals

patASTtoTH :: Pat -> Pat Source #

Upgrade patterns.

matchASTtoTH :: Match -> LiftQ Match Source #

Upgrade match-constructs.

decASTtoTH :: Dec -> LiftQ Dec Source #

Upgrade declarations.

expASTtoTH :: Exp -> LiftQ Exp Source #

Upgrade expressions.

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.

liftLitAST :: Lit -> LiftQ Exp Source #

Lifting literals.

liftPatAST :: Pat -> LiftQ Pat Source #

Lifting patterns.

liftMatchAST :: Match -> LiftQ Match Source #

Lifting match-constructs.

liftDecAST :: Dec -> LiftQ Dec Source #

Lifting declarations.

liftFirstLevelDecAST :: Dec -> LiftQ Dec Source #

Lifting first-level declarations.

liftExpAST :: Exp -> LiftQ Exp Source #

Lifting expressions.

makeDecTemplate :: Dec -> LiftQ Dec Source #

make a declaration into a template-declaration (by renaming with the template-prefix).

Various pretty printing functions

prettyPrintAST :: Q [Dec] -> IO () Source #

pretty-printing Template Haskell declarations.

prettyPrintLiftExpTH :: Q Exp -> IO () Source #

Pretty-printing Template Haskell expressions.

prettyPrintLiftExpAST :: LiftQ Exp -> IO () Source #

Pretty-printing expressions.

The main lifting functions.

decToMonad :: String -> Q [Dec] -> Q [Dec] Source #

Lift a list of declarations. The first argument is the name of the monad to lift into.

expToMonad :: String -> Q Exp -> Q Exp Source #

Lift an expression. The first argument is the name of the monad to lift into.