Module AbstractCurry.Transform

This library provides transformation and update operations on AbstractCurry programs. Since the transformations are defined recursively on structured types, they are useful to construct specific transformations on AbstractCurry programs. In particular, this library contains the transformation renameCurryModule to rename an AbstractCurry module.

Category
meta
Author
Michael Hanus
Version
August 2024

Exported Datatypes


type Update a b = (b -> b) -> a -> a

This type synonym is useful to denote the type of an update, where the first argument is the type of values which are updated by the local update (which acts on types described by the second argument).


Exported Functions


trCProg :: (String -> [String] -> Maybe CDefaultDecl -> [CClassDecl] -> [CInstanceDecl] -> [CTypeDecl] -> [CFuncDecl] -> [COpDecl] -> a) -> CurryProg -> a  Deterministic 

Transforms an AbstractCurry program.


updCProg :: (String -> String) -> ([String] -> [String]) -> (Maybe CDefaultDecl -> Maybe CDefaultDecl) -> ([CClassDecl] -> [CClassDecl]) -> ([CInstanceDecl] -> [CInstanceDecl]) -> ([CTypeDecl] -> [CTypeDecl]) -> ([CFuncDecl] -> [CFuncDecl]) -> ([COpDecl] -> [COpDecl]) -> CurryProg -> CurryProg  Deterministic 

Updates an AbstractCurry program.


updCProgName :: (String -> String) -> CurryProg -> CurryProg  Deterministic 

Updates the name of a Curry program.


trCDefaultDecl :: ([CTypeExpr] -> a) -> CDefaultDecl -> a  Deterministic 

Transforms a default declaration.


updCDefaultDecl :: ([CTypeExpr] -> [CTypeExpr]) -> CDefaultDecl -> CDefaultDecl  Deterministic 

Updates a default declaration.


trCContext :: ([((String, String), [CTypeExpr])] -> a) -> CContext -> a  Deterministic 

Transforms a class context.


updCContext :: ([((String, String), [CTypeExpr])] -> [((String, String), [CTypeExpr])]) -> CContext -> CContext  Deterministic 

Updates a class context.


trCClassDecl :: ((String, String) -> CVisibility -> CContext -> [(Int, String)] -> [([(Int, String)], [(Int, String)])] -> [CFuncDecl] -> a) -> CClassDecl -> a  Deterministic 

Transforms a class declaration.


updCClassDecl :: ((String, String) -> (String, String)) -> (CVisibility -> CVisibility) -> (CContext -> CContext) -> ([(Int, String)] -> [(Int, String)]) -> ([([(Int, String)], [(Int, String)])] -> [([(Int, String)], [(Int, String)])]) -> ([CFuncDecl] -> [CFuncDecl]) -> CClassDecl -> CClassDecl  Deterministic 

Updates a class declaration.


trCInstanceDecl :: ((String, String) -> CContext -> [CTypeExpr] -> [CFuncDecl] -> a) -> CInstanceDecl -> a  Deterministic 

Transforms a class declaration.


updCInstanceDecl :: ((String, String) -> (String, String)) -> (CContext -> CContext) -> ([CTypeExpr] -> [CTypeExpr]) -> ([CFuncDecl] -> [CFuncDecl]) -> CInstanceDecl -> CInstanceDecl  Deterministic 

Updates an AbstractCurry program.


trCTypeDecl :: ((String, String) -> CVisibility -> [(Int, String)] -> [CConsDecl] -> [(String, String)] -> a) -> ((String, String) -> CVisibility -> [(Int, String)] -> CTypeExpr -> a) -> ((String, String) -> CVisibility -> [(Int, String)] -> CConsDecl -> [(String, String)] -> a) -> CTypeDecl -> a  Deterministic 

Transforms a type declaration.


updCTypeDecl :: ((String, String) -> (String, String)) -> (CVisibility -> CVisibility) -> ([(Int, String)] -> [(Int, String)]) -> ([CConsDecl] -> [CConsDecl]) -> (CTypeExpr -> CTypeExpr) -> (CConsDecl -> CConsDecl) -> ([(String, String)] -> [(String, String)]) -> CTypeDecl -> CTypeDecl  Deterministic 

update type declaration


updCTypeDeclName :: ((String, String) -> (String, String)) -> CTypeDecl -> CTypeDecl  Deterministic 

Updates the name of a type declaration.


trCConsDecl :: ((String, String) -> CVisibility -> [CTypeExpr] -> a) -> ((String, String) -> CVisibility -> [CFieldDecl] -> a) -> CConsDecl -> a  Deterministic 

Transforms a constructor declaration.


updCConsDecl :: ((String, String) -> (String, String)) -> (CVisibility -> CVisibility) -> ([CTypeExpr] -> [CTypeExpr]) -> ([CFieldDecl] -> [CFieldDecl]) -> CConsDecl -> CConsDecl  Deterministic 

Updates a constructor declaration.


updCConsDeclName :: ((String, String) -> (String, String)) -> CConsDecl -> CConsDecl  Deterministic 

Updates the name of a constructor declaration.


trCFieldDecl :: ((String, String) -> CVisibility -> CTypeExpr -> a) -> CFieldDecl -> a  Deterministic 

Transforms a constructor declaration.


updCFieldDecl :: ((String, String) -> (String, String)) -> (CVisibility -> CVisibility) -> (CTypeExpr -> CTypeExpr) -> CFieldDecl -> CFieldDecl  Deterministic 

update constructor declaration


updCFieldDeclName :: ((String, String) -> (String, String)) -> CFieldDecl -> CFieldDecl  Deterministic 

Updates the name of a constructor declaration.


trCQualTypeExpr :: (CContext -> CTypeExpr -> a) -> CQualTypeExpr -> a  Deterministic 

Transforms a default declaration.


updCQualTypeExpr :: (CContext -> CContext) -> (CTypeExpr -> CTypeExpr) -> CQualTypeExpr -> CQualTypeExpr  Deterministic 

Updates a default declaration.


trCTypeExpr :: ((Int, String) -> a) -> ((String, String) -> a) -> (a -> a -> a) -> (a -> a -> a) -> CTypeExpr -> a  Deterministic 

Transforms a type expression.


updTConsApp :: ((String, String) -> CTypeExpr) -> CTypeExpr -> CTypeExpr  Deterministic 

Updates all type constructors in a type expression.


trCOpDecl :: ((String, String) -> CFixity -> Int -> a) -> COpDecl -> a  Deterministic 

Transforms an operator declaration.


updCOpDecl :: ((String, String) -> (String, String)) -> (CFixity -> CFixity) -> (Int -> Int) -> COpDecl -> COpDecl  Deterministic 

Updates an operator declaration.


updCOpName :: ((String, String) -> (String, String)) -> COpDecl -> COpDecl  Deterministic 

Updates the name of an operator declaration.


trCFuncDecl :: (String -> (String, String) -> Int -> CVisibility -> CQualTypeExpr -> [CRule] -> a) -> CFuncDecl -> a  Deterministic 

Transforms a function declaration


updCFuncDecl :: (String -> String) -> ((String, String) -> (String, String)) -> (Int -> Int) -> (CVisibility -> CVisibility) -> (CQualTypeExpr -> CQualTypeExpr) -> ([CRule] -> [CRule]) -> CFuncDecl -> CFuncDecl  Deterministic 

Updates a function declaration.


trCRule :: ([CPattern] -> CRhs -> a) -> CRule -> a  Deterministic 

Transform a rule.


updCRule :: ([CPattern] -> [CPattern]) -> (CRhs -> CRhs) -> CRule -> CRule  Deterministic 

Update a rule.


trCRhs :: (CExpr -> [CLocalDecl] -> a) -> ([(CExpr, CExpr)] -> [CLocalDecl] -> a) -> CRhs -> a  Deterministic 

Transforms a right-hand side (of a rule or case expression).


updCRhs :: (CExpr -> CExpr) -> ([(CExpr, CExpr)] -> [(CExpr, CExpr)]) -> ([CLocalDecl] -> [CLocalDecl]) -> CRhs -> CRhs  Deterministic 

Updates right-hand side.


trCLocalDecl :: (CFuncDecl -> a) -> (CPattern -> CRhs -> a) -> ([(Int, String)] -> a) -> CLocalDecl -> a  Deterministic 

Transforms a local declaration.


updCLocalDecl :: (CFuncDecl -> CFuncDecl) -> (CPattern -> CPattern) -> (CRhs -> CRhs) -> ([(Int, String)] -> [(Int, String)]) -> CLocalDecl -> CLocalDecl  Deterministic 

Updates a local declaration.


trCPattern :: ((Int, String) -> a) -> (CLiteral -> a) -> ((String, String) -> [a] -> a) -> ((Int, String) -> a -> a) -> ((String, String) -> [a] -> a) -> ((String, String) -> [((String, String), a)] -> a) -> CPattern -> a  Deterministic 

Transforms a pattern.


updCPattern :: ((Int, String) -> (Int, String)) -> (CLiteral -> CLiteral) -> ((String, String) -> (String, String)) -> CPattern -> CPattern  Deterministic 

Updates a pattern.


trExpr :: ((Int, String) -> a) -> (CLiteral -> a) -> ((String, String) -> a) -> (a -> a -> a) -> ([CPattern] -> a -> a) -> ([CLocalDecl] -> a -> a) -> ([CStatement] -> a) -> (a -> [CStatement] -> a) -> (CCaseType -> a -> [(CPattern, CRhs)] -> a) -> (a -> CQualTypeExpr -> a) -> ((String, String) -> [((String, String), a)] -> a) -> (a -> [((String, String), a)] -> a) -> CExpr -> a  Deterministic 

Transforms an expression.


trCStatement :: (CExpr -> a) -> (CPattern -> CExpr -> a) -> ([CLocalDecl] -> a) -> CStatement -> a  Deterministic 

Transforms a statement (occuring in do expressions or list comprehensions).


updCStatement :: (CExpr -> CExpr) -> (CPattern -> CPattern) -> (CLocalDecl -> CLocalDecl) -> CStatement -> CStatement  Deterministic 

Updates a statement (occuring in do expressions or list comprehensions).


renameCurryModule :: String -> CurryProg -> CurryProg  Deterministic 

Renames a Curry module, i.e., updates the module name and all qualified names in a program.


updQNamesInCProg :: ((String, String) -> (String, String)) -> CurryProg -> CurryProg  Deterministic 

Updates all qualified names in a Curry program.


updQNamesInCDefaultDecl :: ((String, String) -> (String, String)) -> Maybe CDefaultDecl -> Maybe CDefaultDecl  Deterministic 

Updates all qualified names in a default declaration.


updQNamesInCClassDecl :: ((String, String) -> (String, String)) -> CClassDecl -> CClassDecl  Deterministic 

Updates all qualified names in a class declaration.


updQNamesInCInstanceDecl :: ((String, String) -> (String, String)) -> CInstanceDecl -> CInstanceDecl  Deterministic 

Updates all qualified names in an instance declaration.


updQNamesInCTypeDecl :: ((String, String) -> (String, String)) -> CTypeDecl -> CTypeDecl  Deterministic 

Updates all qualified names in a type declaration.


updQNamesInCConsDecl :: ((String, String) -> (String, String)) -> CConsDecl -> CConsDecl  Deterministic 

Updates all qualified names in a constructor declaration.


updQNamesInCContext :: ((String, String) -> (String, String)) -> CContext -> CContext  Deterministic 

Updates all qualified names in a constructor declaration.


updQNamesInCFieldDecl :: ((String, String) -> (String, String)) -> CFieldDecl -> CFieldDecl  Deterministic 

Updates all qualified names in a record field declaration.


updQNamesInCQualTypeExpr :: ((String, String) -> (String, String)) -> CQualTypeExpr -> CQualTypeExpr  Deterministic 

Updates all qualified names in a type expression.


updQNamesInCTypeExpr :: ((String, String) -> (String, String)) -> CTypeExpr -> CTypeExpr  Deterministic 

Updates all qualified names in a type expression.


updQNamesInCFuncDecl :: ((String, String) -> (String, String)) -> CFuncDecl -> CFuncDecl  Deterministic 

Updates all qualified names in a function declaration.


updQNamesInCRule :: ((String, String) -> (String, String)) -> CRule -> CRule  Deterministic 

Updates all qualified names in a function declaration.


updQNamesInCRhs :: ((String, String) -> (String, String)) -> CRhs -> CRhs  Deterministic 

Updates all qualified names in a function declaration.


updQNamesInCLocalDecl :: ((String, String) -> (String, String)) -> CLocalDecl -> CLocalDecl  Deterministic 

Updates all qualified names in a function declaration.


updQNamesInCPattern :: ((String, String) -> (String, String)) -> CPattern -> CPattern  Deterministic 

Updates all qualified names in a function declaration.


updQNamesInCStatement :: ((String, String) -> (String, String)) -> CStatement -> CStatement  Deterministic 

Updates all qualified names in a statement.


updQNamesInCExpr :: ((String, String) -> (String, String)) -> CExpr -> CExpr  Deterministic 


typesOfCurryProg :: CurryProg -> [(String, String)]  Deterministic 

Extracts all type names occurring in a program.


typesOfCClassDecl :: CClassDecl -> [(String, String)]  Deterministic 

Extracts all type names occurring in a class declaration. Class names are ignored.


typesOfCInstanceDecl :: CInstanceDecl -> [(String, String)]  Deterministic 

Extracts all type names occurring in a class declaration. Class names are ignored.


typesOfCTypeDecl :: CTypeDecl -> [(String, String)]  Deterministic 

Extracts all type names occurring in a type declaration. Class names are ignored.


typesOfConsDecl :: CConsDecl -> [(String, String)]  Deterministic 


typesOfFieldDecl :: CFieldDecl -> [(String, String)]  Deterministic 


typesOfContext :: CContext -> [(String, String)]  Deterministic 


typesOfTypeExpr :: CTypeExpr -> [(String, String)]  Deterministic 


typesOfQualTypeExpr :: CQualTypeExpr -> [(String, String)]  Deterministic 


typesOfCFuncDecl :: CFuncDecl -> [(String, String)]  Deterministic 


unionMap :: Eq b => (a -> [b]) -> [a] -> [b]  Deterministic 


funcsOfCurryProg :: CurryProg -> [(String, String)]  Deterministic 

Extracts all function (and constructor) names occurring in a program.


funcsOfCClassDecl :: CClassDecl -> [(String, String)]  Deterministic 


funcsOfCInstanceDecl :: CInstanceDecl -> [(String, String)]  Deterministic 


funcsOfCTypeDecl :: CTypeDecl -> [(String, String)]  Deterministic 


funcsOfConsDecl :: CConsDecl -> [(String, String)]  Deterministic 


funcsOfFieldDecl :: CFieldDecl -> [(String, String)]  Deterministic 


funcsOfCFuncDecl :: CFuncDecl -> [(String, String)]  Deterministic 

Extracts all function (and constructor) names occurring in a function declaration.


funcsOfCRule :: CRule -> [(String, String)]  Deterministic 


funcsOfCRhs :: CRhs -> [(String, String)]  Deterministic 


funcsOfLDecl :: CLocalDecl -> [(String, String)]  Deterministic 


funcsOfExpr :: CExpr -> [(String, String)]  Deterministic 


funcsOfStat :: CStatement -> [(String, String)]  Deterministic