Advertisement

Higher-Order and Symbolic Computation

, Volume 15, Issue 4, pp 273–300 | Cite as

A Generalization of Short-Cut Fusion and its Correctness Proof

  • Patricia Johann
Article

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.

functional programming program transformation polymorphism parametricity operational semantics correctness proofs short-cut fusion theorems for free 

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Abadi, M. TT-closed relations and admissibility. Mathematical Structures in Computer Science, 10 (2000) 313–320.Google Scholar
  2. 2.
    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.Google Scholar
  3. 3.
    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).Google Scholar
  4. 4.
    Chitil, O. Type inference builds a short cut to deforestation. In Proceedings, International Conference on Functional Programming, 1999, pp. 249–260.Google Scholar
  5. 5.
    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.Google Scholar
  6. 6.
    Gill, A. Cheap Deforestation for Non-strict Functional Languages. PhD Thesis, Glasgow University, 1996.Google Scholar
  7. 7.
    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.Google Scholar
  8. 8.
    Hu, Z., Iwasaki, H., and Takeichi, M. Deriving structural hylomorphisms from recursive definitions. In Proceedings, International Conference on Functional Programming, 1996, pp. 73–82.Google Scholar
  9. 9.
    Johann, P. An implementation of warm fusion. Available at ftp://ftp.cse.ogi.edu/pub/pacsoft/ wf/, 1997.Google Scholar
  10. 10.
    Johann, P. Short cut fusion is correct. Journal of Functional Programming. To appear.Google Scholar
  11. 11.
    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.Google Scholar
  12. 12.
    Lassen, S.B. Relational Reasoning about Functions and Nondeterminism. PhD Thesis, University of Aarhus, 1998.Google Scholar
  13. 13.
    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.Google Scholar
  14. 14.
    Mason, I.A., Smith, S.F., and Talcott, C.L. From operational semantics to domain theory. Information and Computation, 128(1) (1996) 26–47.Google Scholar
  15. 15.
    Németh, L. Catamorphism Based Program Transformations for Non-Strict Functional Languages. PhD Thesis, Glasgow University, 2000.Google Scholar
  16. 16.
    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.Google Scholar
  17. 17.
    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.Google Scholar
  18. 18.
    Pitts, A. Parametric polymorphism, recursive types, and operational equivalence. Unpublished Manuscript (1998).Google Scholar
  19. 19.
    Pitts, A. Parametric polymorphism and operational equivalence. Mathematical Structures in Computer Science, 10 (2000) 1–39.Google Scholar
  20. 20.
    Reynolds, J.C. Toward a theory of type structure. Paris Colloquium on Programming, LNCS, Vol. 19, 1974, pp. 408–425.Google Scholar
  21. 21.
    Reynolds, J.C. Types, abstraction, and parametric polymorphism. Information Processing, 83 (1983) 513–523.Google Scholar
  22. 22.
    Sheard, T. and Fegaras, L. A fold for all seasons. In Proceedings, Conference on Functional Programming and Computer Architecture, 1993, pp. 233–242.Google Scholar
  23. 23.
    Takano, A. and Meijer, E. Shortcut deforestation in calculational form. In Proceedings, Conference on Functional Programming and Computer Architecture, 1995, pp. 324–333.Google Scholar
  24. 24.
    Tarski, A. A lattice-theoretical fixpoint theorem and its applications. Pacific Journal of Mathematics, 5 (1955) 285–309.Google Scholar
  25. 25.
    Wadler, P. Theorems for free! In Proceedings, Conference on Functional Programming and Computer Architecture, 1989, pp. 347–359.Google Scholar

Copyright information

© Kluwer Academic Publishers 2002

Authors and Affiliations

  • Patricia Johann
    • 1
  1. 1.Department of Computer ScienceRutgers UniversityCamdenUSA

Personalised recommendations