Warm fusion in Stratego: A case study in generation of program transformation systems

  • Patricia Johann
  • Eelco Visser
Article

Abstract

Stratego is a domain-specific language for the specification of program transformation systems. The design of Stratego is based on the paradigm of rewriting strategies: user-definable programs in a little language of strategy operators determine where and in what order transformation rules are (automatically) applied to a program. The separation of rules and strategies supports modularity of specifications. Stratego also provides generic features for specification of program traversals.

In this paper we present a case study of Stratego as applied to a non-trivial problem in program transformation. We demonstrate the use of Stratego in eliminating intermediate data structures from (also known as deforesting) functional programs via the warm fusion algorithm of Launchbury and Sheard. This algorithm has been specified in Stratego and embedded in a fully automatic transformation system for kernel Haskell. The entire system consists of about 2600 lines of specification code, which breaks down into 1850 lines for a general framework for Haskell transformation and 750 lines devoted to a highly modular, easily extensible specification of the warm fusion transformer itself. Its successful design and construction provides further evidence that programs generated from Stratego specifications are suitable for integration into real systems, and that rewriting strategies are a good paradigm for the implementation of such systems.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. [1]
    A.W. Appel, Compiling with Continuations(Cambridge University Press, 1992).Google Scholar
  2. [2]
    R.M. Burstall and J. Darlington, A transformational system for developing recursive programs, J. of the ACM 24(1) (1977) 44-67.MATHMathSciNetCrossRefGoogle Scholar
  3. [3]
    W.N. Chin, Safe fusion of functional expressions, ACMLisp Pointers 5(1) (1992) 11-20, Proceedings of the 1992 ACM Conference on Lisp and Functional Programming.Google Scholar
  4. [4]
    M. de Jonge, A pretty-printer for every occasion, in: Proceedings of the 2nd International Symposium on Constructing Software Engineering Tools (CoSET2000), eds. I. Ferguson, J. Gray and L. Scott, Limerick, Ireland (June 2000); also: Technical Report, University of Wollongong, Australia.Google Scholar
  5. [5]
    M. Fokkinga, Law and order in algorithmics, Ph.D. thesis, Twente University (1992).Google Scholar
  6. [6]
    P. Fradet and D. Le Métayer, Compilation of functional languages by program transformation, ACM Trans. Programming Languages Syst. 13(1) (1991) 21-51.CrossRefGoogle Scholar
  7. [7]
    A.J. Gill, Cheap deforestation for non-strict functional languages, Ph.D. thesis, University of Glasgow (January 1996).Google Scholar
  8. [8]
    A. Gill, J. Launchbury and S.L. Peyton Jones, A short cut to deforestation, in: Functional Programming Languages and Computer Architecture (FPCA'93), ed. Arvind (ACMPress, 1993) pp. 223-232.Google Scholar
  9. [9]
    T. Hagino, A categorical programming language, Ph.D. thesis, University of Edinburgh (1987).Google Scholar
  10. [10]
    Z. Hu, H. Iwasaki and M. Takeichi, Deriving structural hylomorphisms from recursive definitions, ACM SIGPLAN Notices 31(6) (1996) 73-82, Proceedings of the International Conference on Functional Programming (ICFP'96), Philadelphia.Google Scholar
  11. [11]
    P. Johann, An implementation of warm fusion, available at ftp://ftp.cse.ogi.edu/pub/ pacsoft/wf/ (1997).Google Scholar
  12. [12]
    P. Johann, Short cut fusion is correct, Technical report, Bates College, Lewiston, Maine, USA (2000).Google Scholar
  13. [13]
    P. Johann and E. Visser, Warm fusion in Stratego: A case study in the generation of program transformation systems, Technical report, Institute of Information and Computing Sciences, Universiteit Utrecht, Utrecht, The Netherlands (2000).Google Scholar
  14. [14]
    J. Launchbury and T. Sheard, Warm fusion: Deriving build-catas from recursive definitions, in: Functional Programming Languages and Computer Architecture (FPCA'95), ed. S.L. Peyton Jones (ACM Press, 1995) pp. 314-323.Google Scholar
  15. [15]
    B. Luttik and E. Visser, Specification of rewriting strategies, in: 2nd International Workshop on the Theory and Practice of Algebraic Specifications (ASF+SDF'97), ed. M.P.A. Sellink, ElectronicWorkshops in Computing, Berlin, November 1997 (Springer, Berlin, 1997).Google Scholar
  16. [16]
    G. Malcolm, Homomorphisms and promotability, in: Mathematics of Program Construction, Lecture Notes in Computer Science, Vol. 375 (Springer, Berlin, 1989) pp. 335-347.Google Scholar
  17. [17]
    G.J. Malcolm, Data structures and program transformation, Sci. Comput. Programming 14 (1990) 255-279.MATHMathSciNetCrossRefGoogle Scholar
  18. [18]
    E. Meijer, M. Fokkinga and R. Paterson, Functional programming with bananas, lenses, envelopes and barbed wire, in: Functional Programming and Computer Architecture (FPCA'91), ed. R.J.M. Hughes, Lecture Notes in Computer Science, Vol. 523 (Springer, Berlin, 1991) pp. 124-144.Google Scholar
  19. [19]
    L. Németh, Catamorphism based program transformation for non-strict functional langauges, Draft, Ph.D. thesis, University of Glasgow (2000).Google Scholar
  20. [20]
    W. Partain, The nofib benchmark suite of Haskell programs, in: Functional Programming, eds. J. Launchbury and P.M. Sansom (Springer, Berlin, 1992) pp. 195-202.Google Scholar
  21. [21]
    S. Peyton Jones, J. Hughes et al., Report of the programming language Haskell98 a non-strict, purely functional language (February 1999).Google Scholar
  22. [22]
    S.L. Peyton Jones and J. Launchbury, Unboxed values as first class citizens in a non-strict functional language, in: Functional Programming and Computer Architecture (FPCA'91), ed. R.J.M. Hughes, Lecture Notes in Computer Science, Vol. 523 (Springer, Berlin, 1991) pp. 636-666.Google Scholar
  23. [23]
    S.L. Peyton Jones and A.L.M. Santos, A transformation-based optimiser for Haskell, Sci. Comput. Programming 32(1-3) (1998) 3-47.CrossRefGoogle Scholar
  24. [24]
    T. Sheard and L. Fegaras, A fold for all seasons, in: Functional Programming and Computer Architecture (FPCA'93), ed. Arvind, Copenhagen, Denmark (ACM Press, 1993) pp. 233-242.Google Scholar
  25. [25]
    A. Takano and E. Meijer, Shortcut deforestation in calculational form, in: Functional Programming and Computer Architecture (FPCA'95), ed. S.L. Peyton-Jones, San Diego, CA (June 1995).Google Scholar
  26. [26]
    A. Tolmach and D. Oliva, From ML to Ada: Strongly-typed language interoperability via source translation, J. Funct. Programming 8(4) (1998) 367-412.MATHCrossRefGoogle Scholar
  27. [27]
    V. Turchin, The concept of a supercompiler, ACM Trans. Programming Languages Syst. 8(3) (1986) 292-326.MATHMathSciNetCrossRefGoogle Scholar
  28. [28]
    M.G.J. van den Brand, H.A. de Jong, P. Klint and P.A. Olivier, Efficient annotated terms, Software Practice Exper. 30 (2000) 259-291.CrossRefGoogle Scholar
  29. [29]
    M.G.J. van den Brand and E. Visser, Generation of formatters for context-free languages, ACMTrans. Software Engrg. Methodol. 5(1) (1996) 1-41.CrossRefGoogle Scholar
  30. [30]
    E. Visser, Syntax definition for language prototyping, Ph.D. thesis, University of Amsterdam (September 1997).Google Scholar
  31. [31]
    E. Visser, Strategic pattern matching, in: Rewriting Techniques and Applications (RTA'99), eds. P. Narendran and M. Rusinowitch, Lecture Notes in Computer Science, Vol. 1631, Trento, Italy, July 1999 (Springer, Berlin, 1999) pp. 30-44.Google Scholar
  32. [32]
    E. Visser, The Stratego Library, Institute of Information and Computing Sciences, Universiteit Utrecht, Utrecht, The Netherlands (1999).Google Scholar
  33. [33]
    E. Visser, Language independent traversals for program transformation, in: Workshop on Generic Programming (WGP2000), ed. J. Jeuring, Ponte de Lima, Portugal, July 6 (2000); also: Technical Report UU-CS-2000-19, Universiteit Utrecht.Google Scholar
  34. [34]
    E. Visser and Zine-el-Abidine Benaissa, A core language for rewriting, in: Proceedings of the Second International Workshop on Rewriting Logic and its Applications (WRLA'98), eds. C. Kirchner and H. Kirchner, Electronic Notes in Theoretical Computer Science, Vol. 15 (1998).Google Scholar
  35. [35]
    E. Visser, Zine-el-Abidine Benaissa and A. Tolmach, Building program optimizers with rewriting strategies, ACM SIGPLAN Notices 34(1) (1999) 13-26, Proceedings of the International Conference on Functional Programming (ICFP'98).Google Scholar
  36. [36]
    P. Wadler, Deforestation: Transforming programs to eliminate trees, Theor. Comput. Sci. 73 (1990) 231-248.MATHMathSciNetCrossRefGoogle Scholar
  37. [37]
    www.stratego-language.org.Google Scholar

Copyright information

© Kluwer Academic Publishers 2000

Authors and Affiliations

  • Patricia Johann
    • 1
  • Eelco Visser
    • 2
  1. 1.Department of MathematicsBates CollegeLewistonUSA E-mail
  2. 2.Institute of Information and Computing SciencesUniversiteit UtrechtUtrechtThe Netherlands E-mail

Personalised recommendations