Abstract
Short-cut fusion is a program transformation technique that uses a single, local transformation—called the foldr-build rule—to remove certain intermediate lists from modularly constructed functional programs. Arguments that short-cut fusion is correct typically appeal either to intuition or to “free theorems”—even though the latter have not been known to hold for the languages supporting higher-order polymorphic functions and fixed point recursion in which short-cut fusion is usually applied. In this paper we use Pitts' recent demonstration that contextual equivalence in such languages is relationally parametric to prove that programs in them which have undergone short-cut fusion are contextually equivalent to their unfused counterparts. For each algebraic data type we then define a generalization of build which constructs substitution instances of its associated data structures, and use Pitts' techniques to prove the correctness of a contextual equivalence-preserving fusion rule which generalizes short-cut fusion. These rules optimize compositions of functions that uniformly consume algebraic data structures with functions that uniformly produce substitution instances of those data sructures.
Similar content being viewed by others
References
Abadi, M. TT-closed relations and admissibility. Mathematical Structures in Computer Science, 10 (2000) 313–320.
Bainbridge, E.S., Freyd, P.J., Scedrov, A., and Scott, P.J. Functorial polymorphism. Theoretical Computer Science, 70(1) (1990) 35–64. Corrigendum in 71(3) (1990) 431.
Bierman, G.M., Pitts, A.M., and Russo C.V. Operational semantics of Lily, a polymorphic linear lambda calculus with recursion. Electronic Notes in Theoretical Computer Science, 41(3) (2000).
Chitil, O. Type inference builds a short cut to deforestation. In Proceedings, International Conference on Functional Programming, 1999, pp. 249–260.
Fiore, M. and Plotkin, G. An axiomatization of computationally adequate domain theoretic models of FPC. In Proceedings, 9th Annual Symposium on Logic in Computer Science, 1994, pp. 92–102.
Gill, A. Cheap Deforestation for Non-strict Functional Languages. PhD Thesis, Glasgow University, 1996.
Gill, A., Launchbury, J., and Peyton Jones, S.L. A short cut to deforestation. In Proceedings, Conference on Functional Languages and Computer Architecture, 1993, pp. 223–232.
Hu, Z., Iwasaki, H., and Takeichi, M. Deriving structural hylomorphisms from recursive definitions. In Proceedings, International Conference on Functional Programming, 1996, pp. 73–82.
Johann, P. An implementation of warm fusion. Available at ftp://ftp.cse.ogi.edu/pub/pacsoft/ wf/, 1997.
Johann, P. Short cut fusion is correct. Journal of Functional Programming. To appear.
Johann, P. and Visser, E. Warm fusion in Stratego: A case study in generation of program transformation systems. Annals of Mathematics and Artificial Intelligence, 29(1–4) (2000) 1–34.
Lassen, S.B. Relational Reasoning about Functions and Nondeterminism. PhD Thesis, University of Aarhus, 1998.
Launchbury, J. and Sheard, T. Warm fusion: Deriving build-catas from recursive definitions. In Proceedings, Conference on Functional Programming and Computer Architecture, 1995, pp. 314–323.
Mason, I.A., Smith, S.F., and Talcott, C.L. From operational semantics to domain theory. Information and Computation, 128(1) (1996) 26–47.
Németh, L. Catamorphism Based Program Transformations for Non-Strict Functional Languages. PhD Thesis, Glasgow University, 2000.
Onoue, Y., Hu, Z., Iwasaki, H., and Takeichi, M. A calculational system HYLO. In Proceedings, IFIP TC 2 Working Conference on Algorithmic Languages and Calculi, 1997, pp. 76–106.
Pitts, A. Existential types: Logical relations and operational equivalence. In Proceedings, International Colloquium on Automata, Languages, and Programming, LNCS, Vol. 1443, 1998, pp. 309–326.
Pitts, A. Parametric polymorphism, recursive types, and operational equivalence. Unpublished Manuscript (1998).
Pitts, A. Parametric polymorphism and operational equivalence. Mathematical Structures in Computer Science, 10 (2000) 1–39.
Reynolds, J.C. Toward a theory of type structure. Paris Colloquium on Programming, LNCS, Vol. 19, 1974, pp. 408–425.
Reynolds, J.C. Types, abstraction, and parametric polymorphism. Information Processing, 83 (1983) 513–523.
Sheard, T. and Fegaras, L. A fold for all seasons. In Proceedings, Conference on Functional Programming and Computer Architecture, 1993, pp. 233–242.
Takano, A. and Meijer, E. Shortcut deforestation in calculational form. In Proceedings, Conference on Functional Programming and Computer Architecture, 1995, pp. 324–333.
Tarski, A. A lattice-theoretical fixpoint theorem and its applications. Pacific Journal of Mathematics, 5 (1955) 285–309.
Wadler, P. Theorems for free! In Proceedings, Conference on Functional Programming and Computer Architecture, 1989, pp. 347–359.
Author information
Authors and Affiliations
Rights and permissions
About this article
Cite this article
Johann, P. A Generalization of Short-Cut Fusion and its Correctness Proof. Higher-Order and Symbolic Computation 15, 273–300 (2002). https://doi.org/10.1023/A:1022982420888
Issue Date:
DOI: https://doi.org/10.1023/A:1022982420888