Module FlatCurry.Transform.Types

Author
Michael Hanus, Steven Libby
Version
September 2025

Definition of types used to specify transformations on FlatCurry programs.

Data types for expression transformations


type Path = [Int]

A path to some subepxression is represented by a list of integers.


type Step = (String, Path, Expr)

A transformation step consists of a string, a path, and an expression.


type ExprTransformation = (VarIndex, Path) -> Expr -> (Expr, String, Int)

An expression transformation is a (possibly non-deterministic) operation which takes a pair consisting of a fresh variable index and the position of the expression in the right-hand side and a FlatCurry expression and returns a transformed expression, the name of the applied transformation (just for debugging), and the number of new variables used in the transformation,


type ExprTransformationDet = (VarIndex, Path) -> Expr -> Maybe (Expr, String, Int)

An deterministic expression transformation is an totally defined operation which takes a pair consisting of a fresh variable index and the position of the expression in the right-hand side and a FlatCurry expression and returns a Maybe value. The result is Nothing if the transformation is not applicable, otherwise the result consists of the transformed expression, the name of the applied transformation (for debugging), and the number of new variables used in the transformation,


Operations to lift simple transformations to general ones


makeT :: String -> (Expr -> Expr) -> (Int, [Int]) -> Expr -> (Expr, String, Int)  Deterministic 

Lift a simple transformation on expressions to a general expression transformation (of type ExprTransformation) where the name of the transformation is provided as the first argument.


makeTDet :: String -> (Expr -> Maybe Expr) -> (Int, [Int]) -> Expr -> Maybe (Expr, String, Int)  Deterministic 

Lift a simple deterministic transformation on expressions to a general deterministic expression transformation (of type ExprTransformationDet) where the name of the transformation is provided as the first argument.


Compose deterministic transformations


(<?>) :: ((Int, [Int]) -> Expr -> Maybe (Expr, String, Int)) -> ((Int, [Int]) -> Expr -> Maybe (Expr, String, Int)) -> (Int, [Int]) -> Expr -> Maybe (Expr, String, Int)  Deterministic 

Parallel composition of two deterministic expression transformations where the second transformation is used if the first is not applicable.


combine :: [(Int, [Int]) -> Expr -> Maybe (Expr, String, Int)] -> (Int, [Int]) -> Expr -> Maybe (Expr, String, Int)  Deterministic 

Parallel composition of a sequence of deterministic expression transformations.