This module defines utility functions for working with FlatCurry.
Author: Björn Peemöller
Version: April 2015
progName
:: Prog -> String
Retrieve the module name of a program. |
funcName
:: FuncDecl -> (String,String)
Retrieve the function's name from its declaration. |
isExternal
:: FuncDecl -> Bool
Is a function externally defined? |
hasName
:: (String,String) -> FuncDecl -> Bool
Has a function declaration the given name? |
constructors
:: TypeDecl -> [(String,String)]
Retrieve the constructors of a type. |
maxVar
:: [Int] -> Int
Get the maximum index of all given variables of 0 if the list is empty. |
maxVarIndex
:: Expr -> Int
Get the maximum index of all variables in an expression, or 0 if there is no variable at all. |
maximumVarIndex
:: [Expr] -> Int
Get the maximum index of all variables in a list of expressions, or 0 if there is no variable at all. |
vars
:: Expr -> [Int]
Get all variables of an expression, without duplicates. |
freeVars
:: Expr -> [Int]
Get all free variables of an expression, without duplicates. |
freeVarsDup
:: Expr -> [Int]
Get all free variables of an expression, with duplicates. |
(\\\)
:: [a] -> [a] -> [a]
List difference with duplicates. |
funcsInExps
:: [Expr] -> [(String,String)]
Get all used functions in a list of expression, with duplicates. |
noShadowing
:: Expr -> Bool
Check that no shadowing of variables occurs in the given expression. |
subExprs
:: Expr -> [Expr]
Compute all sub-expressions of an expression. |
isSQ
:: Expr -> Bool
|
getSQ
:: Expr -> Maybe Expr
|
delSQ
:: Expr -> Expr
Deeply delete all square brackets from an expression. |
topSQ
:: Expr -> Expr
Create a square bracket at top-level and delete all other square brackets. |
liftSQ
:: Expr -> Expr
Lift any nested SQ's to top-level or leave the expression as is if there are none. |
sq'
:: Expr -> Expr
We could not compute an appropriate generalization. |
sq
:: Expr -> Expr
Mark an expression for later evaluation when appropriate. |
hasSQ
:: Expr -> Bool
Check whether the expression has a square bracket inside. |
onBranchExps
:: (Expr -> Expr) -> [BranchExpr] -> [BranchExpr]
Apply a function on all branches' expressions. |
unzipBranches
:: [BranchExpr] -> ([Pattern],[Expr])
Unzip a list of branches into a pair of pattern and expression list. |
zipBranches
:: [Pattern] -> [Expr] -> [BranchExpr]
Zip a list of patterns and a list of expressions to a list of branches. |
branchExpr
:: BranchExpr -> Expr
Retrieve a branches' expression. |
branchExprs
:: [BranchExpr] -> [Expr]
Retrieve all branches' expressions. |
branchPats
:: [BranchExpr] -> [Pattern]
Retrieve all branches' patterns. |
eqPattern
:: Pattern -> Pattern -> Bool
Check if two pattern are equal. |
samePattern
:: [BranchExpr] -> [BranchExpr] -> Bool
Do two lists of case branches have the same patterns? |
findBranch
:: Pattern -> [BranchExpr] -> Maybe ([Int],Expr)
Find the matching branch for a given pattern. |
trExpr
:: (Int -> a) -> (Literal -> a) -> (CombType -> (String,String) -> [a] -> a) -> ([Int] -> a -> a) -> (a -> a -> a) -> (CaseType -> a -> [b] -> a) -> (Pattern -> a -> b) -> ([(Int,a)] -> a -> a) -> (a -> TypeExpr -> a) -> Expr -> a
Bottom up transformation on expressions. |
isVar
:: Expr -> Bool
Check whether an expression is a variable |
isLit
:: Expr -> Bool
Check whether an expression is a literal |
isConsCall
:: CombType -> Bool
Check whether a combination is a (partial) constructor call. |
isFuncCall
:: CombType -> Bool
Check whether a combination is a (partial) function call. |
isPartCall
:: CombType -> Bool
Check whether an expression is a partial call. |
isConstrTerm
:: Expr -> Bool
Check whether an expression is a constructor term, i.e, it consists of variables, literals and constructors only. |
patVars
:: Pattern -> [Int]
Extract all variables bound by a pattern. |
addPartCallArg
:: CombType -> (String,String) -> [Expr] -> Expr -> Expr
Add an argument to a PartCall, resulting in either a FuncCall or a PartCall. |
completePartCall
:: CombType -> (String,String) -> [Expr] -> Expr
Completes the arguments of a partcall with fresh variables. |
missingArgs
:: CombType -> Int
Compute the number of missing argument for a function or constructor call. |
pat2exp
:: Pattern -> Expr
Create an expression from a pattern. |
mkFree
:: [Int] -> Expr -> Expr
Smart constructor for Free
expression, returns the expression itself
when no variables are given.
|
mkLet
:: [(Int,Expr)] -> Expr -> Expr
Smart constructor for Let
expression, returns the expression itself
when no declarations are given.
|
mkOr
:: Expr -> Expr -> Expr
Smart constructor for Or
expression, returns one of the argument
sexpressions if the other one equals failed .
|
mkCase
:: CaseType -> Expr -> [BranchExpr] -> Expr
Smart constructor for Case
expression, removes branches directly
calling failed and evaluates to failed
if there are only failing branches.
|
mkLazyBind
:: [(Int,Expr)] -> Expr -> Expr
Add a list of lazy bindings to an expression. |
func
:: (String,String) -> [Expr] -> Expr
Create a function application. |
cons
:: (String,String) -> [Expr] -> Expr
Create a constructor application. |
prelude
:: String -> (String,String)
Qualify an identifier with the "Prelude" module. |
isFailed
:: Expr -> Bool
Is the given expression equal to failed ?
|
trueExpr
:: Expr
Expression representing True .
|
falseExpr
:: Expr
Expression representing False .
|
failedExpr
:: Expr
Expression representing failed .
|
combine
:: (String,String) -> (String,String) -> Expr -> [Expr] -> [Expr] -> Expr
combine inner outer def es1 es2
combines two lists of expressions
es1
and es2
by combining each pair using inner , and then each
combination using outer .
|
mkBool
:: Bool -> Expr
Create a boolean expression based on the specified value. |
(.=:=.)
:: Expr -> Expr -> Expr
Combine two expression using strict unification. |
(.&>.)
:: Expr -> Expr -> Expr
Combine two expression using the cond
operator.
|
prelPEVAL
:: (String,String)
QName
of Prelude.PEVAL
|
prelFalse
:: (String,String)
QName
of Prelude.False
|
prelTrue
:: (String,String)
QName
of Prelude.True
|
prelCond
:: (String,String)
QName
of Prelude.&>
|
prelCond'
:: (String,String)
QName
of Prelude.cond
|
prelAmp
:: (String,String)
QName
of Prelude.&
|
prelEq
:: (String,String)
QName
of Prelude.==
|
prelNeq
:: (String,String)
QName
of Prelude./=
|
prelOr
:: (String,String)
QName
of Prelude.||
|
prelAnd
:: (String,String)
QName
of Prelude.&&
|
prelLt
:: (String,String)
QName
of Prelude.<
|
prelLeq
:: (String,String)
QName
of Prelude.<=
|
prelGt
:: (String,String)
QName
of Prelude.>
|
prelGeq
:: (String,String)
QName
of Prelude.>=
|
prelSuccess
:: (String,String)
QName
of Prelude.success
|
prelFailed
:: (String,String)
QName
of Prelude.failed
|
prelUni
:: (String,String)
QName
of Prelude.=::=
|
prelLazyUni
:: (String,String)
QName
of Prelude.=:<=
|
prelUnknown
:: (String,String)
QName
of Prelude.unknown
|
prelApply
:: (String,String)
QName
of Prelude.apply
|
prelChoice
:: (String,String)
QName
of Prelude.?
|
prelPlus
:: (String,String)
QName
of Prelude.+
|
prelTimes
:: (String,String)
QName
of Prelude.*
|
prelMinus
:: (String,String)
QName
of Prelude.-
|
prelDiv
:: (String,String)
QName
of Prelude.div
|
prelMod
:: (String,String)
QName
of Prelude.mod
|
Retrieve the module name of a program.
|
Retrieve the function's name from its declaration.
|
Is a function externally defined? |
Retrieve the constructors of a type. |
Get the maximum index of all given variables of 0 if the list is empty. |
Get the maximum index of all variables in an expression, or 0 if there is no variable at all. |
Get the maximum index of all variables in a list of expressions, or 0 if there is no variable at all. |
Get all free variables of an expression, with duplicates. |
List difference with duplicates. |
Get all used functions in a list of expression, with duplicates. |
Check that no shadowing of variables occurs in the given expression. |
Lift any nested SQ's to top-level or leave the expression as is if there are none. |
We could not compute an appropriate generalization. To ensure termination, we discard one piece of information and try again. |
Apply a function on all branches' expressions. |
Unzip a list of branches into a pair of pattern and expression list.
|
Zip a list of patterns and a list of expressions to a list of branches. |
Retrieve a branches' expression.
|
Retrieve all branches' expressions. |
Retrieve all branches' patterns. |
Do two lists of case branches have the same patterns? |
Find the matching branch for a given pattern. |
Bottom up transformation on expressions. |
Check whether a combination is a (partial) constructor call. |
Check whether a combination is a (partial) function call. |
Check whether an expression is a partial call. |
Check whether an expression is a constructor term, i.e, it consists of variables, literals and constructors only. |
Extract all variables bound by a pattern.
|
Add an argument to a PartCall, resulting in either a FuncCall or a PartCall. |
Completes the arguments of a partcall with fresh variables. /Note:/ There is no guarantee that the new variables are globally fresh, so they must not be used afterwards. |
Compute the number of missing argument for a function or constructor call. |
Smart constructor for |
Smart constructor for |
Smart constructor for |
Smart constructor for |
Add a list of lazy bindings to an expression. |
Create a function application.
|
Create a constructor application.
|
Qualify an identifier with the "Prelude" module.
|
Expression representing |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|