This library provides selector functions, test and update operations as well as some useful auxiliary functions for FlatCurry 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 FlatCurry 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: Sebastian Fischer, Bjoern Peemoeller
Version: October 2015
| trProg
                  ::  (String -> [String] -> [TypeDecl] -> [AFuncDecl a] -> [OpDecl] -> b) -> AProg a -> btransform program | 
| progName
                  ::  AProg a -> Stringget name from program | 
| progImports
                  ::  AProg a -> [String]get imports from program | 
| progTypes
                  ::  AProg a -> [TypeDecl]get type declarations from program | 
| progFuncs
                  ::  AProg a -> [AFuncDecl a]get functions from program | 
| progOps
                  ::  AProg a -> [OpDecl]get infix operators from program | 
| updProg
                  ::  (String -> String) -> ([String] -> [String]) -> ([TypeDecl] -> [TypeDecl]) -> ([AFuncDecl a] -> [AFuncDecl a]) -> ([OpDecl] -> [OpDecl]) -> AProg a -> AProg aupdate program | 
| updProgName
                  ::  (String -> String) -> AProg a -> AProg aupdate name of program | 
| updProgImports
                  ::  ([String] -> [String]) -> AProg a -> AProg aupdate imports of program | 
| updProgTypes
                  ::  ([TypeDecl] -> [TypeDecl]) -> AProg a -> AProg aupdate type declarations of program | 
| updProgFuncs
                  ::  ([AFuncDecl a] -> [AFuncDecl a]) -> AProg a -> AProg aupdate functions of program | 
| updProgOps
                  ::  ([OpDecl] -> [OpDecl]) -> AProg a -> AProg aupdate infix operators of program | 
| allVarsInProg
                  ::  AProg a -> [Int]get all program variables (also from patterns) | 
| updProgExps
                  ::  (AExpr a -> AExpr a) -> AProg a -> AProg alift transformation on expressions to program | 
| rnmAllVarsInProg
                  ::  (Int -> Int) -> AProg a -> AProg arename programs variables | 
| updQNamesInProg
                  ::  ((String,String) -> (String,String)) -> AProg a -> AProg aupdate all qualified names in program | 
| rnmProg
                  ::  String -> AProg a -> AProg arename program (update name of and all qualified names in program) | 
| trType
                  ::  ((String,String) -> Visibility -> [Int] -> [ConsDecl] -> a) -> ((String,String) -> Visibility -> [Int] -> TypeExpr -> a) -> TypeDecl -> atransform type declaration | 
| typeName
                  ::  TypeDecl -> (String,String)get name of type declaration | 
| typeVisibility
                  ::  TypeDecl -> Visibilityget visibility of type declaration | 
| typeParams
                  ::  TypeDecl -> [Int]get type parameters of type declaration | 
| typeConsDecls
                  ::  TypeDecl -> [ConsDecl]get constructor declarations from type declaration | 
| typeSyn
                  ::  TypeDecl -> TypeExprget synonym of type declaration | 
| isTypeSyn
                  ::  TypeDecl -> Boolis type declaration a type synonym? | 
| updType
                  ::  ((String,String) -> (String,String)) -> (Visibility -> Visibility) -> ([Int] -> [Int]) -> ([ConsDecl] -> [ConsDecl]) -> (TypeExpr -> TypeExpr) -> TypeDecl -> TypeDeclupdate type declaration | 
| updTypeName
                  ::  ((String,String) -> (String,String)) -> TypeDecl -> TypeDeclupdate name of type declaration | 
| updTypeVisibility
                  ::  (Visibility -> Visibility) -> TypeDecl -> TypeDeclupdate visibility of type declaration | 
| updTypeParams
                  ::  ([Int] -> [Int]) -> TypeDecl -> TypeDeclupdate type parameters of type declaration | 
| updTypeConsDecls
                  ::  ([ConsDecl] -> [ConsDecl]) -> TypeDecl -> TypeDeclupdate constructor declarations of type declaration | 
| updTypeSynonym
                  ::  (TypeExpr -> TypeExpr) -> TypeDecl -> TypeDeclupdate synonym of type declaration | 
| updQNamesInType
                  ::  ((String,String) -> (String,String)) -> TypeDecl -> TypeDeclupdate all qualified names in type declaration | 
| trCons
                  ::  ((String,String) -> Int -> Visibility -> [TypeExpr] -> a) -> ConsDecl -> atransform constructor declaration | 
| consName
                  ::  ConsDecl -> (String,String)get name of constructor declaration | 
| consArity
                  ::  ConsDecl -> Intget arity of constructor declaration | 
| consVisibility
                  ::  ConsDecl -> Visibilityget visibility of constructor declaration | 
| consArgs
                  ::  ConsDecl -> [TypeExpr]get arguments of constructor declaration | 
| updCons
                  ::  ((String,String) -> (String,String)) -> (Int -> Int) -> (Visibility -> Visibility) -> ([TypeExpr] -> [TypeExpr]) -> ConsDecl -> ConsDeclupdate constructor declaration | 
| updConsName
                  ::  ((String,String) -> (String,String)) -> ConsDecl -> ConsDeclupdate name of constructor declaration | 
| updConsArity
                  ::  (Int -> Int) -> ConsDecl -> ConsDeclupdate arity of constructor declaration | 
| updConsVisibility
                  ::  (Visibility -> Visibility) -> ConsDecl -> ConsDeclupdate visibility of constructor declaration | 
| updConsArgs
                  ::  ([TypeExpr] -> [TypeExpr]) -> ConsDecl -> ConsDeclupdate arguments of constructor declaration | 
| updQNamesInConsDecl
                  ::  ((String,String) -> (String,String)) -> ConsDecl -> ConsDeclupdate all qualified names in constructor declaration | 
| tVarIndex
                  ::  TypeExpr -> Intget index from type variable | 
| domain
                  ::  TypeExpr -> TypeExprget domain from functional type | 
| range
                  ::  TypeExpr -> TypeExprget range from functional type | 
| tConsName
                  ::  TypeExpr -> (String,String)get name from constructed type | 
| tConsArgs
                  ::  TypeExpr -> [TypeExpr]get arguments from constructed type | 
| trTypeExpr
                  ::  (Int -> a) -> ((String,String) -> [a] -> a) -> (a -> a -> a) -> ([Int] -> a -> a) -> TypeExpr -> atransform type expression | 
| isTVar
                  ::  TypeExpr -> Boolis type expression a type variable? | 
| isTCons
                  ::  TypeExpr -> Boolis type declaration a constructed type? | 
| isFuncType
                  ::  TypeExpr -> Boolis type declaration a functional type? | 
| isForallType
                  ::  TypeExpr -> Boolis type declaration a forall type? | 
| updTVars
                  ::  (Int -> TypeExpr) -> TypeExpr -> TypeExprupdate all type variables | 
| updTCons
                  ::  ((String,String) -> [TypeExpr] -> TypeExpr) -> TypeExpr -> TypeExprupdate all type constructors | 
| updFuncTypes
                  ::  (TypeExpr -> TypeExpr -> TypeExpr) -> TypeExpr -> TypeExprupdate all functional types | 
| updForallTypes
                  ::  ([Int] -> TypeExpr -> TypeExpr) -> TypeExpr -> TypeExprupdate all forall types | 
| argTypes
                  ::  TypeExpr -> [TypeExpr]get argument types from functional type | 
| resultType
                  ::  TypeExpr -> TypeExprget result type from (nested) functional type | 
| rnmAllVarsInTypeExpr
                  ::  (Int -> Int) -> TypeExpr -> TypeExprrename variables in type expression | 
| updQNamesInTypeExpr
                  ::  ((String,String) -> (String,String)) -> TypeExpr -> TypeExprupdate all qualified names in type expression | 
| trOp
                  ::  ((String,String) -> Fixity -> Int -> a) -> OpDecl -> atransform operator declaration | 
| opName
                  ::  OpDecl -> (String,String)get name from operator declaration | 
| opFixity
                  ::  OpDecl -> Fixityget fixity of operator declaration | 
| opPrecedence
                  ::  OpDecl -> Intget precedence of operator declaration | 
| updOp
                  ::  ((String,String) -> (String,String)) -> (Fixity -> Fixity) -> (Int -> Int) -> OpDecl -> OpDeclupdate operator declaration | 
| updOpName
                  ::  ((String,String) -> (String,String)) -> OpDecl -> OpDeclupdate name of operator declaration | 
| updOpFixity
                  ::  (Fixity -> Fixity) -> OpDecl -> OpDeclupdate fixity of operator declaration | 
| updOpPrecedence
                  ::  (Int -> Int) -> OpDecl -> OpDeclupdate precedence of operator declaration | 
| trFunc
                  ::  ((String,String) -> Int -> Visibility -> TypeExpr -> ARule a -> b) -> AFuncDecl a -> btransform function | 
| funcName
                  ::  AFuncDecl a -> (String,String)get name of function | 
| funcArity
                  ::  AFuncDecl a -> Intget arity of function | 
| funcVisibility
                  ::  AFuncDecl a -> Visibilityget visibility of function | 
| funcType
                  ::  AFuncDecl a -> TypeExprget type of function | 
| funcRule
                  ::  AFuncDecl a -> ARule aget rule of function | 
| updFunc
                  ::  ((String,String) -> (String,String)) -> (Int -> Int) -> (Visibility -> Visibility) -> (TypeExpr -> TypeExpr) -> (ARule a -> ARule a) -> AFuncDecl a -> AFuncDecl aupdate function | 
| updFuncName
                  ::  ((String,String) -> (String,String)) -> AFuncDecl a -> AFuncDecl aupdate name of function | 
| updFuncArity
                  ::  (Int -> Int) -> AFuncDecl a -> AFuncDecl aupdate arity of function | 
| updFuncVisibility
                  ::  (Visibility -> Visibility) -> AFuncDecl a -> AFuncDecl aupdate visibility of function | 
| updFuncType
                  ::  (TypeExpr -> TypeExpr) -> AFuncDecl a -> AFuncDecl aupdate type of function | 
| updFuncRule
                  ::  (ARule a -> ARule a) -> AFuncDecl a -> AFuncDecl aupdate rule of function | 
| isExternal
                  ::  AFuncDecl a -> Boolis function externally defined? | 
| allVarsInFunc
                  ::  AFuncDecl a -> [Int]get variable names in a function declaration | 
| funcArgs
                  ::  AFuncDecl a -> [(Int,a)]get arguments of function, if not externally defined | 
| funcBody
                  ::  AFuncDecl a -> AExpr aget body of function, if not externally defined | 
| funcRHS
                  ::  AFuncDecl a -> [AExpr a] | 
| rnmAllVarsInFunc
                  ::  (Int -> Int) -> AFuncDecl a -> AFuncDecl arename all variables in function | 
| updQNamesInFunc
                  ::  ((String,String) -> (String,String)) -> AFuncDecl a -> AFuncDecl aupdate all qualified names in function | 
| updFuncArgs
                  ::  ([(Int,a)] -> [(Int,a)]) -> AFuncDecl a -> AFuncDecl aupdate arguments of function, if not externally defined | 
| updFuncBody
                  ::  (AExpr a -> AExpr a) -> AFuncDecl a -> AFuncDecl aupdate body of function, if not externally defined | 
| trRule
                  ::  (a -> [(Int,a)] -> AExpr a -> b) -> (a -> String -> b) -> ARule a -> btransform rule | 
| ruleArgs
                  ::  ARule a -> [(Int,a)]get rules arguments if it's not external | 
| ruleBody
                  ::  ARule a -> AExpr aget rules body if it's not external | 
| ruleExtDecl
                  ::  ARule a -> Stringget rules external declaration | 
| isRuleExternal
                  ::  ARule a -> Boolis rule external? | 
| updRule
                  ::  (a -> a) -> ([(Int,a)] -> [(Int,a)]) -> (AExpr a -> AExpr a) -> (String -> String) -> ARule a -> ARule aupdate rule | 
| updRuleArgs
                  ::  ([(Int,a)] -> [(Int,a)]) -> ARule a -> ARule aupdate rules arguments | 
| updRuleBody
                  ::  (AExpr a -> AExpr a) -> ARule a -> ARule aupdate rules body | 
| updRuleExtDecl
                  ::  (String -> String) -> ARule a -> ARule aupdate rules external declaration | 
| allVarsInRule
                  ::  ARule a -> [Int]get variable names in a functions rule | 
| rnmAllVarsInRule
                  ::  (Int -> Int) -> ARule a -> ARule arename all variables in rule | 
| updQNamesInRule
                  ::  ((String,String) -> (String,String)) -> ARule a -> ARule aupdate all qualified names in rule | 
| trCombType
                  ::  a -> (Int -> a) -> a -> (Int -> a) -> CombType -> atransform combination type | 
| isCombTypeFuncCall
                  ::  CombType -> Boolis type of combination FuncCall? | 
| isCombTypeFuncPartCall
                  ::  CombType -> Boolis type of combination FuncPartCall? | 
| isCombTypeConsCall
                  ::  CombType -> Boolis type of combination ConsCall? | 
| isCombTypeConsPartCall
                  ::  CombType -> Boolis type of combination ConsPartCall? | 
| missingArgs
                  ::  CombType -> Int | 
| varNr
                  ::  AExpr a -> Intget internal number of variable | 
| literal
                  ::  AExpr a -> Literalget literal if expression is literal expression | 
| combType
                  ::  AExpr a -> CombTypeget combination type of a combined expression | 
| combName
                  ::  AExpr a -> (String,String)get name of a combined expression | 
| combArgs
                  ::  AExpr a -> [AExpr a]get arguments of a combined expression | 
| missingCombArgs
                  ::  AExpr a -> Intget number of missing arguments if expression is combined | 
| letBinds
                  ::  AExpr a -> [((Int,a),AExpr a)]get indices of variables in let declaration | 
| letBody
                  ::  AExpr a -> AExpr aget body of let declaration | 
| freeVars
                  ::  AExpr a -> [Int]get variable indices from declaration of free variables | 
| freeExpr
                  ::  AExpr a -> AExpr aget expression from declaration of free variables | 
| orExps
                  ::  AExpr a -> [AExpr a]get expressions from or-expression | 
| caseType
                  ::  AExpr a -> CaseTypeget case-type of case expression | 
| caseExpr
                  ::  AExpr a -> AExpr aget scrutinee of case expression | 
| caseBranches
                  ::  AExpr a -> [ABranchExpr a] | 
| isVar
                  ::  AExpr a -> Boolis expression a variable? | 
| isLit
                  ::  AExpr a -> Boolis expression a literal expression? | 
| isComb
                  ::  AExpr a -> Boolis expression combined? | 
| isLet
                  ::  AExpr a -> Boolis expression a let expression? | 
| isFree
                  ::  AExpr a -> Boolis expression a declaration of free variables? | 
| isOr
                  ::  AExpr a -> Boolis expression an or-expression? | 
| isCase
                  ::  AExpr a -> Boolis expression a case expression? | 
| trExpr
                  ::  (a -> Int -> b) -> (a -> Literal -> b) -> (a -> CombType -> ((String,String),a) -> [b] -> b) -> (a -> [((Int,a),b)] -> b -> b) -> (a -> [(Int,a)] -> b -> b) -> (a -> b -> b -> b) -> (a -> CaseType -> b -> [c] -> b) -> (APattern a -> b -> c) -> (a -> b -> TypeExpr -> b) -> AExpr a -> btransform expression | 
| updVars
                  ::  (a -> Int -> AExpr a) -> AExpr a -> AExpr aupdate all variables in given expression | 
| updLiterals
                  ::  (a -> Literal -> AExpr a) -> AExpr a -> AExpr aupdate all literals in given expression | 
| updCombs
                  ::  (a -> CombType -> ((String,String),a) -> [AExpr a] -> AExpr a) -> AExpr a -> AExpr aupdate all combined expressions in given expression | 
| updLets
                  ::  (a -> [((Int,a),AExpr a)] -> AExpr a -> AExpr a) -> AExpr a -> AExpr aupdate all let expressions in given expression | 
| updFrees
                  ::  (a -> [(Int,a)] -> AExpr a -> AExpr a) -> AExpr a -> AExpr aupdate all free declarations in given expression | 
| updOrs
                  ::  (a -> AExpr a -> AExpr a -> AExpr a) -> AExpr a -> AExpr aupdate all or expressions in given expression | 
| updCases
                  ::  (a -> CaseType -> AExpr a -> [ABranchExpr a] -> AExpr a) -> AExpr a -> AExpr aupdate all case expressions in given expression | 
| updBranches
                  ::  (APattern a -> AExpr a -> ABranchExpr a) -> AExpr a -> AExpr aupdate all case branches in given expression | 
| updTypeds
                  ::  (a -> AExpr a -> TypeExpr -> AExpr a) -> AExpr a -> AExpr aupdate all typed expressions in given expression | 
| isFuncCall
                  ::  AExpr a -> Boolis expression a call of a function where all arguments are provided? | 
| isFuncPartCall
                  ::  AExpr a -> Boolis expression a partial function call? | 
| isConsCall
                  ::  AExpr a -> Boolis expression a call of a constructor? | 
| isConsPartCall
                  ::  AExpr a -> Boolis expression a partial constructor call? | 
| isGround
                  ::  AExpr a -> Boolis expression fully evaluated? | 
| allVars
                  ::  AExpr a -> [Int]get all variables (also pattern variables) in expression | 
| rnmAllVars
                  ::  (Int -> Int) -> AExpr a -> AExpr arename all variables (also in patterns) in expression | 
| updQNames
                  ::  ((String,String) -> (String,String)) -> AExpr a -> AExpr aupdate all qualified names in expression | 
| trBranch
                  ::  (APattern a -> AExpr a -> b) -> ABranchExpr a -> btransform branch expression | 
| branchPattern
                  ::  ABranchExpr a -> APattern aget pattern from branch expression | 
| branchExpr
                  ::  ABranchExpr a -> AExpr aget expression from branch expression | 
| updBranch
                  ::  (APattern a -> APattern a) -> (AExpr a -> AExpr a) -> ABranchExpr a -> ABranchExpr aupdate branch expression | 
| updBranchPattern
                  ::  (APattern a -> APattern a) -> ABranchExpr a -> ABranchExpr aupdate pattern of branch expression | 
| updBranchExpr
                  ::  (AExpr a -> AExpr a) -> ABranchExpr a -> ABranchExpr aupdate expression of branch expression | 
| trPattern
                  ::  (a -> ((String,String),a) -> [(Int,a)] -> b) -> (a -> Literal -> b) -> APattern a -> btransform pattern | 
| patCons
                  ::  APattern a -> (String,String)get name from constructor pattern | 
| patArgs
                  ::  APattern a -> [(Int,a)]get arguments from constructor pattern | 
| patLiteral
                  ::  APattern a -> Literalget literal from literal pattern | 
| isConsPattern
                  ::  APattern a -> Boolis pattern a constructor pattern? | 
| updPattern
                  ::  (((String,String),a) -> ((String,String),a)) -> ([(Int,a)] -> [(Int,a)]) -> (Literal -> Literal) -> APattern a -> APattern aupdate pattern | 
| updPatCons
                  ::  ((String,String) -> (String,String)) -> APattern a -> APattern aupdate constructors name of pattern | 
| updPatArgs
                  ::  ([(Int,a)] -> [(Int,a)]) -> APattern a -> APattern aupdate arguments of constructor pattern | 
| updPatLiteral
                  ::  (Literal -> Literal) -> APattern a -> APattern aupdate literal of pattern | 
| patExpr
                  ::  APattern a -> AExpr abuild expression from pattern | 
| annRule
                  ::  ARule a -> a | 
| annExpr
                  ::  AExpr a -> aExtract the annotation of an annotated expression. | 
| annPattern
                  ::  APattern a -> aExtract the annotation of an annotated pattern. | 
| unAnnProg
                  ::  AProg a -> Prog | 
| unAnnFuncDecl
                  ::  AFuncDecl a -> FuncDecl | 
| unAnnRule
                  ::  ARule a -> Rule | 
| unAnnExpr
                  ::  AExpr a -> Expr | 
| unAnnPattern
                  ::  APattern a -> Pattern | 
              Type synonym: Update a b = (b -> b) -> a -> a
            
| 
                       transform program | 
| 
                       get imports 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 type declaration | 
| 
                       get visibility of type declaration | 
| 
                       get type parameters of type declaration | 
| 
                       get constructor declarations from type declaration | 
| 
                       update type declaration | 
| 
                       update name of type declaration | 
| 
                       update visibility of type declaration | 
| 
                       update type parameters of type declaration | 
| 
                       update constructor declarations of type declaration | 
| 
                       update synonym of type declaration | 
| 
                       update all qualified names in type declaration | 
| 
                       transform constructor declaration | 
| 
                       get visibility of constructor declaration | 
| 
                       update constructor declaration | 
| 
                       update name of constructor declaration | 
| 
                       update arity of constructor declaration | 
| 
                       update visibility of constructor declaration | 
| 
                       update arguments of constructor declaration | 
| 
                       update all qualified names in constructor declaration | 
| 
                       transform type expression | 
| 
                       is type declaration a functional type? | 
| 
                       is type declaration a forall type? | 
| 
                       update all type constructors | 
| 
                       update all functional types | 
| 
                       update all forall types | 
| 
                       get argument types from functional type 
 | 
| 
                       get result type from (nested) functional type 
 | 
| 
                       rename variables in type expression | 
| 
                       update all qualified names in type expression | 
| 
                       get precedence of operator declaration | 
| 
                       update operator declaration | 
| 
                       update name of operator declaration | 
| 
                       update fixity of operator declaration | 
| 
                       update precedence of operator declaration | 
| 
                       transform function | 
| 
                       get visibility 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 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 | 
| 
                       get rules external declaration | 
| 
                       is rule external? | 
| 
                       update rule | 
| 
                       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 | 
| 
                       transform combination type | 
| 
                       is type of combination FuncCall? | 
| 
                       is type of combination FuncPartCall? | 
| 
                       is type of combination ConsCall? | 
| 
                       is type of combination ConsPartCall? | 
| 
                       | 
| 
                       get number of missing arguments if expression is combined | 
| 
                       | 
| 
                       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 or expressions 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 constructors name of pattern | 
| 
                       update arguments of constructor pattern | 
| 
                       update literal of pattern | 
| Extract the annotation of an annotated expression. 
 | 
| 
                       Extract the annotation of an annotated pattern. 
 | 
| 
                       | 
| 
                       |