Module FlatCurry.Typed.Goodies

Category
meta
Author
Kai-Oliver Prott
Version
October 2015

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.

Exported Functions


trTProg :: (String -> [String] -> [TypeDecl] -> [TFuncDecl] -> [OpDecl] -> a) -> TProg -> a  Deterministic 

transform program


tProgName :: TProg -> String  Deterministic 

get name from program


tProgImports :: TProg -> [String]  Deterministic 

get imports from program


tProgTypes :: TProg -> [TypeDecl]  Deterministic 

get type declarations from program


tProgTFuncs :: TProg -> [TFuncDecl]  Deterministic 

get functions from program


tProgOps :: TProg -> [OpDecl]  Deterministic 

get infix operators from program


updTProg :: (String -> String) -> ([String] -> [String]) -> ([TypeDecl] -> [TypeDecl]) -> ([TFuncDecl] -> [TFuncDecl]) -> ([OpDecl] -> [OpDecl]) -> TProg -> TProg  Deterministic 

update program


updTProgName :: (String -> String) -> TProg -> TProg  Deterministic 

update name of program


updTProgImports :: ([String] -> [String]) -> TProg -> TProg  Deterministic 

update imports of program


updTProgTypes :: ([TypeDecl] -> [TypeDecl]) -> TProg -> TProg  Deterministic 

update type declarations of program


updTProgTFuncs :: ([TFuncDecl] -> [TFuncDecl]) -> TProg -> TProg  Deterministic 

update functions of program


updTProgOps :: ([OpDecl] -> [OpDecl]) -> TProg -> TProg  Deterministic 

update infix operators of program


allVarsInTProg :: TProg -> [(Int, TypeExpr)]  Deterministic 

get all program variables (also from patterns)


updTProgTExps :: (TExpr -> TExpr) -> TProg -> TProg  Deterministic 

lift transformation on expressions to program


rnmAllVarsInTProg :: (Int -> Int) -> TProg -> TProg  Deterministic 

rename programs variables


updQNamesInTProg :: ((String, String) -> (String, String)) -> TProg -> TProg  Deterministic 

update all qualified names in program


rnmTProg :: String -> TProg -> TProg  Deterministic 

rename program (update name of and all qualified names in program)


trTFunc :: ((String, String) -> Int -> Visibility -> TypeExpr -> TRule -> a) -> TFuncDecl -> a  Deterministic 

transform function


tFuncName :: TFuncDecl -> (String, String)  Deterministic 

get name of function


tFuncArity :: TFuncDecl -> Int  Deterministic 

get arity of function


tFuncVisibility :: TFuncDecl -> Visibility  Deterministic 

get visibility of function


tFuncType :: TFuncDecl -> TypeExpr  Deterministic 

get type of function


tFuncTRule :: TFuncDecl -> TRule  Deterministic 

get rule of function


updTFunc :: ((String, String) -> (String, String)) -> (Int -> Int) -> (Visibility -> Visibility) -> (TypeExpr -> TypeExpr) -> (TRule -> TRule) -> TFuncDecl -> TFuncDecl  Deterministic 

update function


updTFuncName :: ((String, String) -> (String, String)) -> TFuncDecl -> TFuncDecl  Deterministic 

update name of function


updTFuncArity :: (Int -> Int) -> TFuncDecl -> TFuncDecl  Deterministic 

update arity of function


updTFuncVisibility :: (Visibility -> Visibility) -> TFuncDecl -> TFuncDecl  Deterministic 

update visibility of function


updFuncType :: (TypeExpr -> TypeExpr) -> TFuncDecl -> TFuncDecl  Deterministic 

update type of function


updTFuncTRule :: (TRule -> TRule) -> TFuncDecl -> TFuncDecl  Deterministic 

update rule of function


isPublicTFunc :: TFuncDecl -> Bool  Deterministic 

is function public?


isExternal :: TFuncDecl -> Bool  Deterministic 

is function externally defined?


allVarsInTFunc :: TFuncDecl -> [(Int, TypeExpr)]  Deterministic 

get variable names in a function declaration


tFuncArgs :: TFuncDecl -> [(Int, TypeExpr)]  Deterministic 

get arguments of function, if not externally defined


tFuncBody :: TFuncDecl -> TExpr  Deterministic 

get body of function, if not externally defined


tFuncRHS :: TFuncDecl -> [TExpr]  Deterministic 

get the right-hand-sides of a FuncDecl

Further infos:
  • partially defined

rnmAllVarsInTFunc :: (Int -> Int) -> TFuncDecl -> TFuncDecl  Deterministic 

rename all variables in function


updQNamesInTFunc :: ((String, String) -> (String, String)) -> TFuncDecl -> TFuncDecl  Deterministic 

update all qualified names in function


updTFuncArgs :: ([(Int, TypeExpr)] -> [(Int, TypeExpr)]) -> TFuncDecl -> TFuncDecl  Deterministic 

update arguments of function, if not externally defined


updTFuncBody :: (TExpr -> TExpr) -> TFuncDecl -> TFuncDecl  Deterministic 

update body of function, if not externally defined


trTRule :: ([(Int, TypeExpr)] -> TExpr -> a) -> (TypeExpr -> String -> a) -> TRule -> a  Deterministic 

transform rule


tRuleArgs :: TRule -> [(Int, TypeExpr)]  Deterministic 

get rules arguments if it's not external


tRuleBody :: TRule -> TExpr  Deterministic 

get rules body if it's not external


tRuleExtDecl :: TRule -> String  Deterministic 

get rules external declaration


isTRuleExternal :: TRule -> Bool  Deterministic 

is rule external?


updTRule :: (TypeExpr -> TypeExpr) -> ([(Int, TypeExpr)] -> [(Int, TypeExpr)]) -> (TExpr -> TExpr) -> (String -> String) -> TRule -> TRule  Deterministic 

update rule


updTRuleType :: (TypeExpr -> TypeExpr) -> TRule -> TRule  Deterministic 

update rules TypeExpr


updTRuleArgs :: ([(Int, TypeExpr)] -> [(Int, TypeExpr)]) -> TRule -> TRule  Deterministic 

update rules arguments


updTRuleBody :: (TExpr -> TExpr) -> TRule -> TRule  Deterministic 

update rules body


updTRuleExtDecl :: (String -> String) -> TRule -> TRule  Deterministic 

update rules external declaration


allVarsInTRule :: TRule -> [(Int, TypeExpr)]  Deterministic 

get variable names in a functions rule


rnmAllVarsInTRule :: (Int -> Int) -> TRule -> TRule  Deterministic 

rename all variables in rule


updQNamesInTRule :: ((String, String) -> (String, String)) -> TRule -> TRule  Deterministic 

update all qualified names in rule


varNr :: TExpr -> Int  Deterministic 

get internal number of variable


literal :: TExpr -> Literal  Deterministic 

get literal if expression is literal expression


combType :: TExpr -> CombType  Deterministic 

get combination type of a combined expression


combName :: TExpr -> (String, String)  Deterministic 

get name of a combined expression


combArgs :: TExpr -> [TExpr]  Deterministic 

get arguments of a combined expression


missingCombArgs :: TExpr -> Int  Deterministic 

get number of missing arguments if expression is combined


letBinds :: TExpr -> [((Int, TypeExpr), TExpr)]  Deterministic 

get indices of variables in let declaration


letBody :: TExpr -> TExpr  Deterministic 

get body of let declaration


freeVars :: TExpr -> [(Int, TypeExpr)]  Deterministic 

get variable indices from declaration of free variables


freeExpr :: TExpr -> TExpr  Deterministic 

get expression from declaration of free variables


orExps :: TExpr -> [TExpr]  Deterministic 

get expressions from or-expression


caseType :: TExpr -> CaseType  Deterministic 

get case-type of case expression


caseExpr :: TExpr -> TExpr  Deterministic 

get scrutinee of case expression


caseBranches :: TExpr -> [TBranchExpr]  Deterministic 

get branch expressions from case expression


isTVarE :: TExpr -> Bool  Deterministic 

is expression a variable?


isTLit :: TExpr -> Bool  Deterministic 

is expression a literal expression?


isTComb :: TExpr -> Bool  Deterministic 

is expression combined?


isTLet :: TExpr -> Bool  Deterministic 

is expression a let expression?


isTFree :: TExpr -> Bool  Deterministic 

is expression a declaration of free variables?


isTOr :: TExpr -> Bool  Deterministic 

is expression an or-expression?


isTCase :: TExpr -> Bool  Deterministic 

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  Deterministic 

transform expression


updVars :: (TypeExpr -> Int -> TExpr) -> TExpr -> TExpr  Deterministic 

update all variables in given expression


updLiterals :: (TypeExpr -> Literal -> TExpr) -> TExpr -> TExpr  Deterministic 

update all literals in given expression


updCombs :: (TypeExpr -> CombType -> (String, String) -> [TExpr] -> TExpr) -> TExpr -> TExpr  Deterministic 

update all combined expressions in given expression


updLets :: ([((Int, TypeExpr), TExpr)] -> TExpr -> TExpr) -> TExpr -> TExpr  Deterministic 

update all let expressions in given expression


updFrees :: ([(Int, TypeExpr)] -> TExpr -> TExpr) -> TExpr -> TExpr  Deterministic 

update all free declarations in given expression


updOrs :: (TExpr -> TExpr -> TExpr) -> TExpr -> TExpr  Deterministic 

update all or expressions in given expression


updCases :: (CaseType -> TExpr -> [TBranchExpr] -> TExpr) -> TExpr -> TExpr  Deterministic 

update all case expressions in given expression


updBranches :: (TPattern -> TExpr -> TBranchExpr) -> TExpr -> TExpr  Deterministic 

update all case branches in given expression


updTypeds :: (TExpr -> TypeExpr -> TExpr) -> TExpr -> TExpr  Deterministic 

update all typed expressions in given expression


isFuncCall :: TExpr -> Bool  Deterministic 

is expression a call of a function where all arguments are provided?


isFuncPartCall :: TExpr -> Bool  Deterministic 

is expression a partial function call?


isConsCall :: TExpr -> Bool  Deterministic 

is expression a call of a constructor?


isConsPartCall :: TExpr -> Bool  Deterministic 

is expression a partial constructor call?


isGround :: TExpr -> Bool  Deterministic 

is expression fully evaluated?


allVars :: TExpr -> [(Int, TypeExpr)]  Deterministic 

get all variables (also pattern variables) in expression


rnmAllVars :: (Int -> Int) -> TExpr -> TExpr  Deterministic 

rename all variables (also in patterns) in expression


updQNames :: ((String, String) -> (String, String)) -> TExpr -> TExpr  Deterministic 

update all qualified names in expression


trTBranch :: (TPattern -> TExpr -> a) -> TBranchExpr -> a  Deterministic 

transform branch expression


tBranchTPattern :: TBranchExpr -> TPattern  Deterministic 

get pattern from branch expression


tBranchTExpr :: TBranchExpr -> TExpr  Deterministic 

get expression from branch expression


updTBranch :: (TPattern -> TPattern) -> (TExpr -> TExpr) -> TBranchExpr -> TBranchExpr  Deterministic 

update branch expression


updTBranchTPattern :: (TPattern -> TPattern) -> TBranchExpr -> TBranchExpr  Deterministic 

update pattern of branch expression


updTBranchTExpr :: (TExpr -> TExpr) -> TBranchExpr -> TBranchExpr  Deterministic 

update expression of branch expression


trTPattern :: (TypeExpr -> (String, String) -> [(Int, TypeExpr)] -> a) -> (TypeExpr -> Literal -> a) -> TPattern -> a  Deterministic 

transform pattern


tPatCons :: TPattern -> (String, String)  Deterministic 

get name from constructor pattern


tPatArgs :: TPattern -> [(Int, TypeExpr)]  Deterministic 

get arguments from constructor pattern


tPatLiteral :: TPattern -> Literal  Deterministic 

get literal from literal pattern


isConsPattern :: TPattern -> Bool  Deterministic 

is pattern a constructor pattern?


updTPattern :: (TypeExpr -> TypeExpr) -> ((String, String) -> (String, String)) -> ([(Int, TypeExpr)] -> [(Int, TypeExpr)]) -> (Literal -> Literal) -> TPattern -> TPattern  Deterministic 

update pattern


updTPatType :: (TypeExpr -> TypeExpr) -> TPattern -> TPattern  Deterministic 

update TypeExpr of pattern


updTPatCons :: ((String, String) -> (String, String)) -> TPattern -> TPattern  Deterministic 

update constructors name of pattern


updTPatArgs :: ([(Int, TypeExpr)] -> [(Int, TypeExpr)]) -> TPattern -> TPattern  Deterministic 

update arguments of constructor pattern


updTPatLiteral :: (Literal -> Literal) -> TPattern -> TPattern  Deterministic 

update literal of pattern


tPatExpr :: TPattern -> TExpr  Deterministic 

build expression from pattern