Functional Logic Program Transformations
Michael Hanus, Steven Libby
TL;DR
This paper demonstrates how functional logic programming, as embodied by Curry and its FlatCurry intermediate representation, can simplify the design of program transformations. By modeling transformations as partially defined, non-deterministic operations and tracking subexpression paths and fresh variables, the authors provide a composable, extensible framework for transformation rules. They introduce a formal transformation type, a reusable transformation library, and multiple evaluation strategies (chaotic, deterministic, mixed) to study tradeoffs between readability and performance. Empirical assessments on standard libraries show deterministic and mixed strategies perform well, with non-determinism offering readability benefits and practical viability in modern Curry toolchains like KiCS2 and PAKCS. The approach supports extending transformations to richer analyses and optimizations, as evidenced by its use in the RICE Curry compiler for ANF conversion and related optimizations.
Abstract
Many tools used to process programs, like compilers, analyzers, or verifiers, perform transformations on their intermediate program representation, like abstract syntax trees. Implementing such program transformations is a non-trivial task, since it is necessary to iterate over the complete syntax tree and apply various transformations at nodes in a tree. In this paper we show how the features of functional logic programming are useful to implement program transformations in a compact and comprehensible manner. For this purpose, we propose to write program transformations as partially defined and non-deterministic operations. Since the implementation of non-determinism usually causes some overhead compared to deterministically defined operations, we compare our approach to a deterministic transformation method. We evaluate these alternatives for the functional logic language Curry and its intermediate representation FlatCurry which is used in various analysis and verification tools and compilers.
