This library provides selector functions, test and update operations as well as some useful auxiliary functions for TypedFlatCurry data terms. Most of the provided functions are based on general transformation functions that replace constructors with user-defined functions. For recursive datatypes the transformations are defined inductively over the term structure. This is quite usual for transformations on TypedFlatCurry terms, so the provided functions can be used to implement specific transformations without having to explicitly state the recursion. Essentially, the tedious part of such transformations - descend in fairly complex term structures - is abstracted away, which hopefully makes the code more clear and brief.
Author: Kai-Oliver Prott
Version: October 2015
trTProg
:: (String -> [String] -> [TypeDecl] -> [TFuncDecl] -> [OpDecl] -> a) -> TProg -> a transform program |
tProgName
:: TProg -> String get name from program |
tProgImports
:: TProg -> [String] get imports from program |
tProgTypes
:: TProg -> [TypeDecl] get type declarations from program |
tProgTFuncs
:: TProg -> [TFuncDecl] get functions from program |
tProgOps
:: TProg -> [OpDecl] get infix operators from program |
updTProg
:: (String -> String) -> ([String] -> [String]) -> ([TypeDecl] -> [TypeDecl]) -> ([TFuncDecl] -> [TFuncDecl]) -> ([OpDecl] -> [OpDecl]) -> TProg -> TProg update program |
updTProgName
:: (String -> String) -> TProg -> TProg update name of program |
updTProgImports
:: ([String] -> [String]) -> TProg -> TProg update imports of program |
updTProgTypes
:: ([TypeDecl] -> [TypeDecl]) -> TProg -> TProg update type declarations of program |
updTProgTFuncs
:: ([TFuncDecl] -> [TFuncDecl]) -> TProg -> TProg update functions of program |
updTProgOps
:: ([OpDecl] -> [OpDecl]) -> TProg -> TProg update infix operators of program |
allVarsInTProg
:: TProg -> [(Int,TypeExpr)] get all program variables (also from patterns) |
updTProgTExps
:: (TExpr -> TExpr) -> TProg -> TProg lift transformation on expressions to program |
rnmAllVarsInTProg
:: (Int -> Int) -> TProg -> TProg rename programs variables |
updQNamesInTProg
:: ((String,String) -> (String,String)) -> TProg -> TProg update all qualified names in program |
rnmTProg
:: String -> TProg -> TProg rename program (update name of and all qualified names in program) |
trTFunc
:: ((String,String) -> Int -> Visibility -> TypeExpr -> TRule -> a) -> TFuncDecl -> a transform function |
tFuncName
:: TFuncDecl -> (String,String) get name of function |
tFuncArity
:: TFuncDecl -> Int get arity of function |
tFuncVisibility
:: TFuncDecl -> Visibility get visibility of function |
tFuncType
:: TFuncDecl -> TypeExpr get type of function |
tFuncTRule
:: TFuncDecl -> TRule get rule of function |
updTFunc
:: ((String,String) -> (String,String)) -> (Int -> Int) -> (Visibility -> Visibility) -> (TypeExpr -> TypeExpr) -> (TRule -> TRule) -> TFuncDecl -> TFuncDecl update function |
updTFuncName
:: ((String,String) -> (String,String)) -> TFuncDecl -> TFuncDecl update name of function |
updTFuncArity
:: (Int -> Int) -> TFuncDecl -> TFuncDecl update arity of function |
updTFuncVisibility
:: (Visibility -> Visibility) -> TFuncDecl -> TFuncDecl update visibility of function |
updFuncType
:: (TypeExpr -> TypeExpr) -> TFuncDecl -> TFuncDecl update type of function |
updTFuncTRule
:: (TRule -> TRule) -> TFuncDecl -> TFuncDecl update rule of function |
isPublicTFunc
:: TFuncDecl -> Bool is function public? |
isExternal
:: TFuncDecl -> Bool is function externally defined? |
allVarsInTFunc
:: TFuncDecl -> [(Int,TypeExpr)] get variable names in a function declaration |
tFuncArgs
:: TFuncDecl -> [(Int,TypeExpr)] get arguments of function, if not externally defined |
tFuncBody
:: TFuncDecl -> TExpr get body of function, if not externally defined |
tFuncRHS
:: TFuncDecl -> [TExpr] get the right-hand-sides of a FuncDecl |
rnmAllVarsInTFunc
:: (Int -> Int) -> TFuncDecl -> TFuncDecl rename all variables in function |
updQNamesInTFunc
:: ((String,String) -> (String,String)) -> TFuncDecl -> TFuncDecl update all qualified names in function |
updTFuncArgs
:: ([(Int,TypeExpr)] -> [(Int,TypeExpr)]) -> TFuncDecl -> TFuncDecl update arguments of function, if not externally defined |
updTFuncBody
:: (TExpr -> TExpr) -> TFuncDecl -> TFuncDecl update body of function, if not externally defined |
trTRule
:: ([(Int,TypeExpr)] -> TExpr -> a) -> (TypeExpr -> String -> a) -> TRule -> a transform rule |
tRuleArgs
:: TRule -> [(Int,TypeExpr)] get rules arguments if it's not external |
tRuleBody
:: TRule -> TExpr get rules body if it's not external |
tRuleExtDecl
:: TRule -> String get rules external declaration |
isTRuleExternal
:: TRule -> Bool is rule external? |
updTRule
:: (TypeExpr -> TypeExpr) -> ([(Int,TypeExpr)] -> [(Int,TypeExpr)]) -> (TExpr -> TExpr) -> (String -> String) -> TRule -> TRule update rule |
updTRuleType
:: (TypeExpr -> TypeExpr) -> TRule -> TRule update rules TypeExpr |
updTRuleArgs
:: ([(Int,TypeExpr)] -> [(Int,TypeExpr)]) -> TRule -> TRule update rules arguments |
updTRuleBody
:: (TExpr -> TExpr) -> TRule -> TRule update rules body |
updTRuleExtDecl
:: (String -> String) -> TRule -> TRule update rules external declaration |
allVarsInTRule
:: TRule -> [(Int,TypeExpr)] get variable names in a functions rule |
rnmAllVarsInTRule
:: (Int -> Int) -> TRule -> TRule rename all variables in rule |
updQNamesInTRule
:: ((String,String) -> (String,String)) -> TRule -> TRule update all qualified names in rule |
varNr
:: TExpr -> Int get internal number of variable |
literal
:: TExpr -> Literal get literal if expression is literal expression |
combType
:: TExpr -> CombType get combination type of a combined expression |
combName
:: TExpr -> (String,String) get name of a combined expression |
combArgs
:: TExpr -> [TExpr] get arguments of a combined expression |
missingCombArgs
:: TExpr -> Int get number of missing arguments if expression is combined |
letBinds
:: TExpr -> [((Int,TypeExpr),TExpr)] get indices of variables in let declaration |
letBody
:: TExpr -> TExpr get body of let declaration |
freeVars
:: TExpr -> [(Int,TypeExpr)] get variable indices from declaration of free variables |
freeExpr
:: TExpr -> TExpr get expression from declaration of free variables |
orExps
:: TExpr -> [TExpr] get expressions from or-expression |
caseType
:: TExpr -> CaseType get case-type of case expression |
caseExpr
:: TExpr -> TExpr get scrutinee of case expression |
caseBranches
:: TExpr -> [TBranchExpr] get branch expressions from case expression |
isTVarE
:: TExpr -> Bool is expression a variable? |
isTLit
:: TExpr -> Bool is expression a literal expression? |
isTComb
:: TExpr -> Bool is expression combined? |
isTLet
:: TExpr -> Bool is expression a let expression? |
isTFree
:: TExpr -> Bool is expression a declaration of free variables? |
isTOr
:: TExpr -> Bool is expression an or-expression? |
isTCase
:: TExpr -> Bool is expression a case expression? |
trTExpr
:: (TypeExpr -> Int -> a) -> (TypeExpr -> Literal -> a) -> (TypeExpr -> CombType -> (String,String) -> [a] -> a) -> ([((Int,TypeExpr),a)] -> a -> a) -> ([(Int,TypeExpr)] -> a -> a) -> (a -> a -> a) -> (CaseType -> a -> [b] -> a) -> (TPattern -> a -> b) -> (a -> TypeExpr -> a) -> TExpr -> a transform expression |
updVars
:: (TypeExpr -> Int -> TExpr) -> TExpr -> TExpr update all variables in given expression |
updLiterals
:: (TypeExpr -> Literal -> TExpr) -> TExpr -> TExpr update all literals in given expression |
updCombs
:: (TypeExpr -> CombType -> (String,String) -> [TExpr] -> TExpr) -> TExpr -> TExpr update all combined expressions in given expression |
updLets
:: ([((Int,TypeExpr),TExpr)] -> TExpr -> TExpr) -> TExpr -> TExpr update all let expressions in given expression |
updFrees
:: ([(Int,TypeExpr)] -> TExpr -> TExpr) -> TExpr -> TExpr update all free declarations in given expression |
updOrs
:: (TExpr -> TExpr -> TExpr) -> TExpr -> TExpr update all or expressions in given expression |
updCases
:: (CaseType -> TExpr -> [TBranchExpr] -> TExpr) -> TExpr -> TExpr update all case expressions in given expression |
updBranches
:: (TPattern -> TExpr -> TBranchExpr) -> TExpr -> TExpr update all case branches in given expression |
updTypeds
:: (TExpr -> TypeExpr -> TExpr) -> TExpr -> TExpr update all typed expressions in given expression |
isFuncCall
:: TExpr -> Bool is expression a call of a function where all arguments are provided? |
isFuncPartCall
:: TExpr -> Bool is expression a partial function call? |
isConsCall
:: TExpr -> Bool is expression a call of a constructor? |
isConsPartCall
:: TExpr -> Bool is expression a partial constructor call? |
isGround
:: TExpr -> Bool is expression fully evaluated? |
allVars
:: TExpr -> [(Int,TypeExpr)] get all variables (also pattern variables) in expression |
rnmAllVars
:: (Int -> Int) -> TExpr -> TExpr rename all variables (also in patterns) in expression |
updQNames
:: ((String,String) -> (String,String)) -> TExpr -> TExpr update all qualified names in expression |
trTBranch
:: (TPattern -> TExpr -> a) -> TBranchExpr -> a transform branch expression |
tBranchTPattern
:: TBranchExpr -> TPattern get pattern from branch expression |
tBranchTExpr
:: TBranchExpr -> TExpr get expression from branch expression |
updTBranch
:: (TPattern -> TPattern) -> (TExpr -> TExpr) -> TBranchExpr -> TBranchExpr update branch expression |
updTBranchTPattern
:: (TPattern -> TPattern) -> TBranchExpr -> TBranchExpr update pattern of branch expression |
updTBranchTExpr
:: (TExpr -> TExpr) -> TBranchExpr -> TBranchExpr update expression of branch expression |
trTPattern
:: (TypeExpr -> (String,String) -> [(Int,TypeExpr)] -> a) -> (TypeExpr -> Literal -> a) -> TPattern -> a transform pattern |
tPatCons
:: TPattern -> (String,String) get name from constructor pattern |
tPatArgs
:: TPattern -> [(Int,TypeExpr)] get arguments from constructor pattern |
tPatLiteral
:: TPattern -> Literal get literal from literal pattern |
isConsPattern
:: TPattern -> Bool is pattern a constructor pattern? |
updTPattern
:: (TypeExpr -> TypeExpr) -> ((String,String) -> (String,String)) -> ([(Int,TypeExpr)] -> [(Int,TypeExpr)]) -> (Literal -> Literal) -> TPattern -> TPattern update pattern |
updTPatType
:: (TypeExpr -> TypeExpr) -> TPattern -> TPattern update TypeExpr of pattern |
updTPatCons
:: ((String,String) -> (String,String)) -> TPattern -> TPattern update constructors name of pattern |
updTPatArgs
:: ([(Int,TypeExpr)] -> [(Int,TypeExpr)]) -> TPattern -> TPattern update arguments of constructor pattern |
updTPatLiteral
:: (Literal -> Literal) -> TPattern -> TPattern update literal of pattern |
tPatExpr
:: TPattern -> TExpr build expression from pattern |
transform program |
get imports from program |
get type declarations from program |
get functions from program |
update program |
update name of program |
update imports of program |
update type declarations of program |
update functions of program |
update infix operators of program |
get all program variables (also from patterns) |
lift transformation on expressions to program |
rename programs variables |
update all qualified names in program |
rename program (update name of and all qualified names in program) |
transform function |
get arity of function |
get visibility of function |
get rule of function |
update function |
update name of function |
update arity of function |
update visibility of function |
update type of function |
update rule of function |
is function public? |
is function externally defined? |
get variable names in a function declaration |
rename all variables in function |
update all qualified names in function |
update arguments of function, if not externally defined |
update body of function, if not externally defined |
transform rule |
get rules external declaration |
is rule external? |
update rule |
update rules TypeExpr |
update rules arguments |
update rules body |
update rules external declaration |
get variable names in a functions rule |
rename all variables in rule |
update all qualified names in rule |
get number of missing arguments if expression is combined |
get branch expressions from case expression |
transform expression |
update all literals in given expression |
update all combined expressions in given expression |
update all let expressions in given expression |
update all free declarations in given expression |
update all case expressions in given expression |
update all case branches in given expression |
update all typed expressions in given expression |
is expression a call of a function where all arguments are provided? |
is expression a partial function call? |
is expression a call of a constructor? |
is expression a partial constructor call? |
rename all variables (also in patterns) in expression |
update all qualified names in expression |
transform branch expression |
get pattern from branch expression |
get expression from branch expression |
update branch expression |
update pattern of branch expression |
update expression of branch expression |
transform pattern |
get literal from literal pattern |
is pattern a constructor pattern? |
update pattern |
update TypeExpr of pattern |
update constructors name of pattern |
update arguments of constructor pattern |
update literal of pattern |