Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
This module contains the definition of expressions for our intermediate language.
Synopsis
- data Expr
- = Con { }
- | Var { }
- | App { }
- | TypeAppExpr { }
- | If { }
- | Case { }
- | Undefined { }
- | ErrorExpr { }
- | Trace { }
- | IntLiteral { }
- | Lambda { }
- | Let {
- exprSrcSpan :: SrcSpan
- letExprBinds :: [Bind]
- letExprIn :: Expr
- exprTypeScheme :: Maybe TypeScheme
- exprType :: Expr -> Maybe Type
- untypedCon :: SrcSpan -> ConName -> Expr
- untypedVar :: SrcSpan -> ConName -> Expr
- untypedApp :: SrcSpan -> Expr -> Expr -> Expr
- untypedTypeAppExpr :: SrcSpan -> Expr -> Type -> Expr
- app :: SrcSpan -> Expr -> [Expr] -> Expr
- varApp :: SrcSpan -> VarName -> [Expr] -> Expr
- conApp :: SrcSpan -> ConName -> [Expr] -> Expr
- visibleTypeApp :: SrcSpan -> Expr -> [Type] -> Expr
- getFuncName :: Expr -> Maybe VarName
- prettyExprPred :: Int -> Expr -> Doc
- prettyExprPred' :: Int -> Expr -> Doc
- data Alt = Alt {
- altSrcSpan :: SrcSpan
- altConPat :: ConPat
- altVarPats :: [VarPat]
- altRhs :: Expr
- data ConPat = ConPat {}
- conPatToExpr :: ConPat -> Expr
- data VarPat = VarPat {}
- varPatName :: VarPat -> Name
- varPatQName :: VarPat -> QName
- varPatToExpr :: VarPat -> Expr
- toVarPat :: String -> VarPat
- data Bind = Bind {
- bindSrcSpan :: SrcSpan
- bindVarPat :: VarPat
- bindExpr :: Expr
Documentation
An expression.
Con | A constructor. |
Var | A function or local variable. |
App | Function or constructor application. |
| |
TypeAppExpr | Visible type application. |
If |
|
| |
Case |
|
| |
Undefined | Error term |
ErrorExpr | Error term |
Trace | Effect |
| |
IntLiteral | An integer literal. |
Lambda | A lambda abstraction. |
| |
Let | A let expression. |
|
Instances
Eq Expr Source # | |
Show Expr Source # | |
Pretty Expr Source # | Pretty instance for expressions. If the expression contains type annotations, the output quickly becomes practically unreadable. Consider stripping type annotations before pretty printing (see FreeC.IR.Strip) to improve readability. |
Defined in FreeC.IR.Syntax.Expr | |
StripExprType Expr Source # | Strips the type annotation of the given expression and of its sub-expressions recursively. |
Defined in FreeC.IR.Strip stripExprType :: Expr -> Expr Source # | |
Similar Expr Source # | The similarity relation of expressions is governed by the the following inference rules
|
Defined in FreeC.IR.Similar | |
HasRefs Expr Source # | Expression refer to the used variables and constructors as wells as the types used in type signatures and visible type applications. The error terms |
Defined in FreeC.IR.Reference | |
Parseable Expr Source # | Expressions can be parsed. |
Defined in FreeC.Frontend.IR.Parser | |
ApplySubst Type Expr Source # | Applies the given type substitution to an expression. |
Defined in FreeC.IR.Subst | |
ApplySubst Expr Bind Source # | Applies the given expression substitution to an the right-hand side of a
The variable that is bound by the binding is not renamed by this instance.
The |
Defined in FreeC.IR.Subst | |
ApplySubst Expr Alt Source # | Applies the given expression substitution to the right-hand side of the
given |
Defined in FreeC.IR.Subst | |
ApplySubst Expr Expr Source # | Applies the given expression substitution to an expression. This function uses the |
Defined in FreeC.IR.Subst | |
ApplySubst Expr FuncDecl Source # | Applies the given expression substitution to the right-hand side of a function declaration. |
Defined in FreeC.IR.Subst |
exprType :: Expr -> Maybe Type Source #
Gets the type annotation of the given expression, but discards the
forall
.
Type annotations quantify their type variables usually only if they are used as expression type signatures. The type annotations generated during type inference never quantify their type arguments.
untypedCon :: SrcSpan -> ConName -> Expr Source #
Smart constructor for Con
without the last argument.
untypedVar :: SrcSpan -> ConName -> Expr Source #
Smart constructor for Var
without the last argument.
untypedApp :: SrcSpan -> Expr -> Expr -> Expr Source #
Smart constructor for app
without the last argument.
The type annotation is inferred from the callee's type annotation. If it is annotated with a function type, the created expression is annotated with the function type's result type.
untypedTypeAppExpr :: SrcSpan -> Expr -> Type -> Expr Source #
Smart constructor for TypeAppExpr
without the last argument.
The type annotation of the expression which is visibly applied is used to annotate the type of this expression.
app :: SrcSpan -> Expr -> [Expr] -> Expr Source #
Creates an expression for applying the given expression to the provided arguments.
The given source span is inserted into the generated function application expressions.
If the given expression's type is annotated with a function type, all generated application nodes are annotated with the corresponding result types. If no more argument types can be split off, the types of the remaining arguments are not annotated.
:: SrcSpan | The source span to insert into generated nodes. |
-> VarName | The name of the function to apply. |
-> [Expr] | The arguments to pass to the function. |
-> Expr |
Creates an expression for applying the function with the given name.
The given source span is inserted into the generated function reference and every generated function application.
Since the type of the variable with the given name is not known, no type annotations will be generated.
:: SrcSpan | The source span to insert into generated nodes. |
-> ConName | The name of the constructor to apply. |
-> [Expr] | The arguments to pass to the constructor. |
-> Expr |
Creates a data constructor application expression.
The given source span is inserted into the generated constructor reference and every generated constructor application.
Since the type of the constructor with the given name is not known, no type annotations will be generated.
visibleTypeApp :: SrcSpan -> Expr -> [Type] -> Expr Source #
Creates an expression for passing the type arguments of a function or constructor explicitly.
The given source span is inserted into every generated visible type application node.
If the given expression's type is annotated, all generated visible type application nodes are annotated with the same type.
getFuncName :: Expr -> Maybe VarName Source #
Returns the function name of a function application, or Nothing
if the
given expression is not a function application.
prettyExprPred :: Int -> Expr -> Doc Source #
Pretty prints an expression and adds parentheses if necessary.
The first argument indicates the precedence of the surrounding
context.
* 0
- Top level. No parentheses are necessary.
* 1
- Parentheses are needed around if
and lambda expressions.
* 2
- Parentheses are also needed around function applications.
prettyExprPred' :: Int -> Expr -> Doc Source #
Like prettyExprPred
but ignores outermost type annotations.
One alternative of a case
expression.
Alt | |
|
Instances
Eq Alt Source # | |
Show Alt Source # | |
Pretty Alt Source # | Pretty instance for |
Defined in FreeC.IR.Syntax.Expr | |
Similar Alt Source # | Two alternatives that match the same constructor Γ ∪ { x₁ ↦ y₁, …, xₙ ↦ yₙ } ⊢ e ≈ f, Γ ⊢ p₁ ≈ q₁, …, Γ ⊢ pₙ ≈ qₙ —————————————————————————————————————————————————————————————————— Γ ⊢ C p₁ … pₙ -> e ≈ C q₁ … qₙ -> f where |
Defined in FreeC.IR.Similar | |
HasRefs Alt Source # |
|
Defined in FreeC.IR.Reference | |
ApplySubst Type Alt Source # | Applies the given type substitution to the right-hand side of the
given |
Defined in FreeC.IR.Subst | |
ApplySubst Expr Alt Source # | Applies the given expression substitution to the right-hand side of the
given |
Defined in FreeC.IR.Subst |
A constructor pattern used in an alternative of a case
expression.
The main purpose of this data type is to add location information
to a ConName
.
conPatToExpr :: ConPat -> Expr Source #
Converts a constructor pattern to a constructor expression.
A variable pattern used as an argument to a function, lambda abstraction or constructor pattern.
The variable pattern can optionally have a type signature
or be annotated by a !
.
VarPat | |
|
Instances
Eq VarPat Source # | |
Show VarPat Source # | |
Pretty VarPat Source # | Pretty instance for variable patterns. |
Defined in FreeC.IR.Syntax.Expr | |
HasDeclIdent VarPat Source # | Instance to get the name of a |
Similar VarPat Source # | Two variable patterns are similar if they either both don't have a type annotation or are annotated with similar types. Γ ⊢ τ ≈ τ' ——————————— —————————————————————————— Γ ⊢ x ≈ y Γ ⊢ (x :: τ) ≈ (y :: τ') If one of the patterns has a bang pattern, the other one needs one as well. Γ ⊢ τ ≈ τ' ————————————— ———————————————————————————— Γ ⊢ !x ≈ !y Γ ⊢ !(x :: τ) ≈ !(y :: τ') |
Defined in FreeC.IR.Similar | |
HasRefs VarPat Source # | Variable patterns refer to the types used in their type annotation. |
Defined in FreeC.IR.Reference | |
ApplySubst Type VarPat Source # | Applies the given type substitution to the type annotation of the given variable pattern. |
Defined in FreeC.IR.Subst |
varPatName :: VarPat -> Name Source #
Gets the name of the given variable pattern.
varPatQName :: VarPat -> QName Source #
Gets the qualified name of the given variable pattern.
varPatToExpr :: VarPat -> Expr Source #
Converts a variable pattern to a variable expression.
toVarPat :: String -> VarPat Source #
Converts the given identifier to a variable pattern without type annotation.
A binding of a variable to an expression inside of a let
-expression.
Bind | |
|
Instances
Eq Bind Source # | |
Show Bind Source # | |
Pretty Bind Source # | Pretty instance for |
Defined in FreeC.IR.Syntax.Expr | |
HasDeclIdent Bind Source # | Instance to get the name of a |
Similar Bind Source # | Two Γ' ⊢ p ≈ q , Γ' ⊢ e ≈ f —————————————————————————— Γ ⊢ p = e ≈ q = f |
Defined in FreeC.IR.Similar | |
HasRefs Bind Source # | |
Defined in FreeC.IR.Reference | |
ApplySubst Type Bind Source # | Applies the given type substitution to the variable pattern and expression
of the given |
Defined in FreeC.IR.Subst | |
ApplySubst Expr Bind Source # | Applies the given expression substitution to an the right-hand side of a
The variable that is bound by the binding is not renamed by this instance.
The |
Defined in FreeC.IR.Subst |