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.

Author: Michael Hanus

Version: April 2016

Summary of exported operations:

trCProg :: (String -> [String] -> [CTypeDecl] -> [CFuncDecl] -> [COpDecl] -> a) -> CurryProg -> a   
Transforms an AbstractCurry program.
updCProg :: (String -> String) -> ([String] -> [String]) -> ([CTypeDecl] -> [CTypeDecl]) -> ([CFuncDecl] -> [CFuncDecl]) -> ([COpDecl] -> [COpDecl]) -> CurryProg -> CurryProg   
Updates an AbstractCurry program.
updCProgName :: (String -> String) -> CurryProg -> CurryProg   
Updates the name of a Curry program.
trCTypeDecl :: ((String,String) -> CVisibility -> [(Int,String)] -> [CConsDecl] -> a) -> ((String,String) -> CVisibility -> [(Int,String)] -> CTypeExpr -> a) -> ((String,String) -> CVisibility -> [(Int,String)] -> CConsDecl -> a) -> CTypeDecl -> a   
Transforms a type declaration.
updCTypeDecl :: ((String,String) -> (String,String)) -> (CVisibility -> CVisibility) -> ([(Int,String)] -> [(Int,String)]) -> ([CConsDecl] -> [CConsDecl]) -> (CTypeExpr -> CTypeExpr) -> (CConsDecl -> CConsDecl) -> CTypeDecl -> CTypeDecl   
update type declaration
updCTypeDeclName :: ((String,String) -> (String,String)) -> CTypeDecl -> CTypeDecl   
Updates the name of a type declaration.
trCConsDecl :: ((String,String) -> CVisibility -> [CTypeExpr] -> a) -> ((String,String) -> CVisibility -> [CFieldDecl] -> a) -> CConsDecl -> a   
Transforms a constructor declaration.
updCConsDecl :: ((String,String) -> (String,String)) -> (CVisibility -> CVisibility) -> ([CTypeExpr] -> [CTypeExpr]) -> ([CFieldDecl] -> [CFieldDecl]) -> CConsDecl -> CConsDecl   
Updates a constructor declaration.
updCConsDeclName :: ((String,String) -> (String,String)) -> CConsDecl -> CConsDecl   
Updates the name of a constructor declaration.
trCFieldDecl :: ((String,String) -> CVisibility -> CTypeExpr -> a) -> CFieldDecl -> a   
Transforms a constructor declaration.
updCFieldDecl :: ((String,String) -> (String,String)) -> (CVisibility -> CVisibility) -> (CTypeExpr -> CTypeExpr) -> CFieldDecl -> CFieldDecl   
update constructor declaration
updCFieldDeclName :: ((String,String) -> (String,String)) -> CFieldDecl -> CFieldDecl   
Updates the name of a constructor declaration.
trCTypeExpr :: ((Int,String) -> a) -> ((String,String) -> [a] -> a) -> (a -> a -> a) -> CTypeExpr -> a   
Transforms a type expression.
updTConsApp :: ((String,String) -> [CTypeExpr] -> CTypeExpr) -> CTypeExpr -> CTypeExpr   
Updates all type constructor applications in a type expression.
trCOpDecl :: ((String,String) -> CFixity -> Int -> a) -> COpDecl -> a   
Transforms an operator declaration.
updCOpDecl :: ((String,String) -> (String,String)) -> (CFixity -> CFixity) -> (Int -> Int) -> COpDecl -> COpDecl   
Updates an operator declaration.
updCOpName :: ((String,String) -> (String,String)) -> COpDecl -> COpDecl   
Updates the name of an operator declaration.
trCFuncDecl :: (String -> (String,String) -> Int -> CVisibility -> CTypeExpr -> [CRule] -> a) -> CFuncDecl -> a   
Transforms a function declaration
updCFuncDecl :: (String -> String) -> ((String,String) -> (String,String)) -> (Int -> Int) -> (CVisibility -> CVisibility) -> (CTypeExpr -> CTypeExpr) -> ([CRule] -> [CRule]) -> CFuncDecl -> CFuncDecl   
Updates a function declaration.
trCRule :: ([CPattern] -> CRhs -> a) -> CRule -> a   
Transform a rule.
updCRule :: ([CPattern] -> [CPattern]) -> (CRhs -> CRhs) -> CRule -> CRule   
Update a rule.
trCRhs :: (CExpr -> [CLocalDecl] -> a) -> ([(CExpr,CExpr)] -> [CLocalDecl] -> a) -> CRhs -> a   
Transforms a right-hand side (of a rule or case expression).
updCRhs :: (CExpr -> CExpr) -> ([(CExpr,CExpr)] -> [(CExpr,CExpr)]) -> ([CLocalDecl] -> [CLocalDecl]) -> CRhs -> CRhs   
Updates right-hand side.
trCLocalDecl :: (CFuncDecl -> a) -> (CPattern -> CRhs -> a) -> ([(Int,String)] -> a) -> CLocalDecl -> a   
Transforms a local declaration.
updCLocalDecl :: (CFuncDecl -> CFuncDecl) -> (CPattern -> CPattern) -> (CRhs -> CRhs) -> ([(Int,String)] -> [(Int,String)]) -> CLocalDecl -> CLocalDecl   
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   
Transforms a pattern.
updCPattern :: ((Int,String) -> (Int,String)) -> (CLiteral -> CLiteral) -> ((String,String) -> (String,String)) -> CPattern -> CPattern   
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 -> CTypeExpr -> a) -> ((String,String) -> [((String,String),a)] -> a) -> (a -> [((String,String),a)] -> a) -> CExpr -> a   
Transforms an expression.
trCStatement :: (CExpr -> a) -> (CPattern -> CExpr -> a) -> ([CLocalDecl] -> a) -> CStatement -> a   
Transforms a statement (occuring in do expressions or list comprehensions).
updCStatement :: (CExpr -> CExpr) -> (CPattern -> CPattern) -> (CLocalDecl -> CLocalDecl) -> CStatement -> CStatement   
Updates a statement (occuring in do expressions or list comprehensions).
renameCurryModule :: String -> CurryProg -> CurryProg   
Renames a Curry module, i.e., updates the module name and all qualified names in a program.
updQNamesInCProg :: ((String,String) -> (String,String)) -> CurryProg -> CurryProg   
Updates all qualified names in a Curry program.
updQNamesInCTypeDecl :: ((String,String) -> (String,String)) -> CTypeDecl -> CTypeDecl   
Updates all qualified names in a type declaration.
updQNamesInCConsDecl :: ((String,String) -> (String,String)) -> CConsDecl -> CConsDecl   
Updates all qualified names in a constructor declaration.
updQNamesInCFieldDecl :: ((String,String) -> (String,String)) -> CFieldDecl -> CFieldDecl   
Updates all qualified names in a record field declaration.
updQNamesInCTypeExpr :: ((String,String) -> (String,String)) -> CTypeExpr -> CTypeExpr   
Updates all qualified names in a type expression.
updQNamesInCFuncDecl :: ((String,String) -> (String,String)) -> CFuncDecl -> CFuncDecl   
Updates all qualified names in a function declaration.
updQNamesInCRule :: ((String,String) -> (String,String)) -> CRule -> CRule   
Updates all qualified names in a function declaration.
updQNamesInCRhs :: ((String,String) -> (String,String)) -> CRhs -> CRhs   
Updates all qualified names in a function declaration.
updQNamesInCLocalDecl :: ((String,String) -> (String,String)) -> CLocalDecl -> CLocalDecl   
Updates all qualified names in a function declaration.
updQNamesInCPattern :: ((String,String) -> (String,String)) -> CPattern -> CPattern   
Updates all qualified names in a function declaration.
updQNamesInCStatement :: ((String,String) -> (String,String)) -> CStatement -> CStatement   
Updates all qualified names in a statement.
updQNamesInCExpr :: ((String,String) -> (String,String)) -> CExpr -> CExpr   
typesOfCurryProg :: CurryProg -> [(String,String)]   
Extracts all type names occurring in a program.
typesOfCTypeDecl :: CTypeDecl -> [(String,String)]   
Extracts all type names occurring in a type declaration.
typesOfConsDecl :: CConsDecl -> [(String,String)]   
typesOfFieldDecl :: CFieldDecl -> [(String,String)]   
typesOfTypeExpr :: CTypeExpr -> [(String,String)]   
typesOfCFuncDecl :: CFuncDecl -> [(String,String)]   
funcsOfCurryProg :: CurryProg -> [(String,String)]   
Extracts all function (and constructor) names occurring in a program.
funcsOfCTypeDecl :: CTypeDecl -> [(String,String)]   
funcsOfConsDecl :: CConsDecl -> [(String,String)]   
funcsOfFieldDecl :: CFieldDecl -> [(String,String)]   
funcsOfCFuncDecl :: CFuncDecl -> [(String,String)]   
Extracts all function (and constructor) names occurring in a function declaration.
funcsOfCRule :: CRule -> [(String,String)]   
funcsOfCRhs :: CRhs -> [(String,String)]   
funcsOfLDecl :: CLocalDecl -> [(String,String)]   
funcsOfExpr :: CExpr -> [(String,String)]   
funcsOfStat :: CStatement -> [(String,String)]   

Exported datatypes:


Update

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).

Type synonym: Update a b = (b -> b) -> a -> a


Exported operations:

trCProg :: (String -> [String] -> [CTypeDecl] -> [CFuncDecl] -> [COpDecl] -> a) -> CurryProg -> a   

Transforms an AbstractCurry program.

updCProg :: (String -> String) -> ([String] -> [String]) -> ([CTypeDecl] -> [CTypeDecl]) -> ([CFuncDecl] -> [CFuncDecl]) -> ([COpDecl] -> [COpDecl]) -> CurryProg -> CurryProg   

Updates an AbstractCurry program.

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

Updates the name of a Curry program.

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

Transforms a type declaration.

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

update type declaration

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

Updates the name of a type declaration.

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

Transforms a constructor declaration.

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

Updates a constructor declaration.

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

Updates the name of a constructor declaration.

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

Transforms a constructor declaration.

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

update constructor declaration

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

Updates the name of a constructor declaration.

trCTypeExpr :: ((Int,String) -> a) -> ((String,String) -> [a] -> a) -> (a -> a -> a) -> CTypeExpr -> a   

Transforms a type expression.

updTConsApp :: ((String,String) -> [CTypeExpr] -> CTypeExpr) -> CTypeExpr -> CTypeExpr   

Updates all type constructor applications in a type expression.

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

Transforms an operator declaration.

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

Updates an operator declaration.

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

Updates the name of an operator declaration.

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

Transforms a function declaration

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

Updates a function declaration.

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

Transform a rule.

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

Update a rule.

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

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

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

Updates right-hand side.

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

Transforms a local declaration.

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

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   

Transforms a pattern.

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

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 -> CTypeExpr -> a) -> ((String,String) -> [((String,String),a)] -> a) -> (a -> [((String,String),a)] -> a) -> CExpr -> a   

Transforms an expression.

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

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

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

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

renameCurryModule :: String -> CurryProg -> CurryProg   

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

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

Updates all qualified names in a Curry program.

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

Updates all qualified names in a type declaration.

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

Updates all qualified names in a constructor declaration.

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

Updates all qualified names in a record field declaration.

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

Updates all qualified names in a type expression.

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

Updates all qualified names in a function declaration.

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

Updates all qualified names in a function declaration.

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

Updates all qualified names in a function declaration.

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

Updates all qualified names in a function declaration.

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

Updates all qualified names in a function declaration.

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

Updates all qualified names in a statement.

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

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

Extracts all type names occurring in a program.

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

Extracts all type names occurring in a type declaration.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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