Module FlatCurryGoodies

This module defines utility functions for working with FlatCurry.

Author: Björn Peemöller

Version: April 2015

Summary of exported operations:

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.
(\\\) :: Eq a => [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

Exported operations:

progName :: Prog -> String   

Retrieve the module name of a program.

Further infos:
  • solution complete, i.e., able to compute all solutions

funcName :: FuncDecl -> (String,String)   

Retrieve the function's name from its declaration.

Further infos:
  • solution complete, i.e., able to compute all solutions

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.

(\\\) :: Eq a => [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. To ensure termination, we discard one piece of information and try again.

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.

Further infos:
  • solution complete, i.e., able to compute all solutions

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.

Further infos:
  • solution complete, i.e., able to compute all solutions

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.

Further infos:
  • solution complete, i.e., able to compute all solutions

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. /Note:/ There is no guarantee that the new variables are globally fresh, so they must not be used afterwards.

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.

Further infos:
  • solution complete, i.e., able to compute all solutions

cons :: (String,String) -> [Expr] -> Expr   

Create a constructor application.

Further infos:
  • solution complete, i.e., able to compute all solutions

prelude :: String -> (String,String)   

Qualify an identifier with the "Prelude" module.

Further infos:
  • solution complete, i.e., able to compute all solutions

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. If es1 or es2 are empty, def is returned.

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

Further infos:
  • solution complete, i.e., able to compute all solutions

prelFalse :: (String,String)   

QName of Prelude.False

Further infos:
  • solution complete, i.e., able to compute all solutions

prelTrue :: (String,String)   

QName of Prelude.True

Further infos:
  • solution complete, i.e., able to compute all solutions

prelCond :: (String,String)   

QName of Prelude.&>

Further infos:
  • solution complete, i.e., able to compute all solutions

prelCond' :: (String,String)   

QName of Prelude.cond

Further infos:
  • solution complete, i.e., able to compute all solutions

prelAmp :: (String,String)   

QName of Prelude.&

Further infos:
  • solution complete, i.e., able to compute all solutions

prelEq :: (String,String)   

QName of Prelude.==

Further infos:
  • solution complete, i.e., able to compute all solutions

prelNeq :: (String,String)   

QName of Prelude./=

Further infos:
  • solution complete, i.e., able to compute all solutions

prelOr :: (String,String)   

QName of Prelude.||

Further infos:
  • solution complete, i.e., able to compute all solutions

prelAnd :: (String,String)   

QName of Prelude.&&

Further infos:
  • solution complete, i.e., able to compute all solutions

prelLt :: (String,String)   

QName of Prelude.<

Further infos:
  • solution complete, i.e., able to compute all solutions

prelLeq :: (String,String)   

QName of Prelude.<=

Further infos:
  • solution complete, i.e., able to compute all solutions

prelGt :: (String,String)   

QName of Prelude.>

Further infos:
  • solution complete, i.e., able to compute all solutions

prelGeq :: (String,String)   

QName of Prelude.>=

Further infos:
  • solution complete, i.e., able to compute all solutions

prelSuccess :: (String,String)   

QName of Prelude.success

Further infos:
  • solution complete, i.e., able to compute all solutions

prelFailed :: (String,String)   

QName of Prelude.failed

Further infos:
  • solution complete, i.e., able to compute all solutions

prelUni :: (String,String)   

QName of Prelude.=::=

Further infos:
  • solution complete, i.e., able to compute all solutions

prelLazyUni :: (String,String)   

QName of Prelude.=:<=

Further infos:
  • solution complete, i.e., able to compute all solutions

prelUnknown :: (String,String)   

QName of Prelude.unknown

Further infos:
  • solution complete, i.e., able to compute all solutions

prelApply :: (String,String)   

QName of Prelude.apply

Further infos:
  • solution complete, i.e., able to compute all solutions

prelChoice :: (String,String)   

QName of Prelude.?

Further infos:
  • solution complete, i.e., able to compute all solutions

prelPlus :: (String,String)   

QName of Prelude.+

Further infos:
  • solution complete, i.e., able to compute all solutions

prelTimes :: (String,String)   

QName of Prelude.*

Further infos:
  • solution complete, i.e., able to compute all solutions

prelMinus :: (String,String)   

QName of Prelude.-

Further infos:
  • solution complete, i.e., able to compute all solutions

prelDiv :: (String,String)   

QName of Prelude.div

Further infos:
  • solution complete, i.e., able to compute all solutions

prelMod :: (String,String)   

QName of Prelude.mod

Further infos:
  • solution complete, i.e., able to compute all solutions