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.
trTProg
:: (String -> [String] -> [TypeDecl] -> [TFuncDecl] -> [OpDecl] -> a) -> TProg -> a
transform program
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
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
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
get internal number of variable
get literal if expression is literal expression
get combination type of a combined expression
combName
:: TExpr -> (String, String)
get name of a combined expression
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
get body of let declaration
freeVars
:: TExpr -> [(Int, TypeExpr)]
get variable indices from declaration of free variables
get expression from declaration of free variables
get expressions from or-expression
get case-type of case expression
get scrutinee of case expression
caseBranches
:: TExpr -> [TBranchExpr]
get branch expressions from case expression
is expression a variable?
is expression a literal expression?
is expression combined?
is expression a let expression?
is expression a declaration of free variables?
is expression an or-expression?
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?
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
build expression from pattern