Skip to main content
Log in

Using Circular Programs to Deforest in Accumulating Parameters

  • Published:
Higher-Order and Symbolic Computation

Abstract

This paper presents a functional program transformation that removes intermediate data structures in compositions of two members of a class of recursive functions with accumulating parameters. To avoid multiple traversals of the input data structure, the composition algorithm produces circular programs that make essential use of lazy evaluation and local recursion. The resulting programs are simplified using a post-processing phase sketched in the paper. The presented transformation, called lazy composition, is compared with related transformation techniques both on a qualitative level and based on runtime measurements. An alternative use of higher-orderedness instead of circularity is also briefly explored.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Similar content being viewed by others

References

  1. Bird, R. Using circular programs to eliminate multiple traversals of data. Acta Informatica, 21(3) (1984) 239-250.

    Google Scholar 

  2. Burstall, R. and Darlington, J. A transformation system for developing recursive programs. J. ACM, 24(1) (1977) 44-67.

    Google Scholar 

  3. Chin, W. Safe fusion of functional expressions II: Further improvements. J. Funct. Prog., 4(4) (1994) 515-555.

    Google Scholar 

  4. Chin, W., Goh, A., and Khoo, S. Effective optimisation of multiple traversals in lazy languages. In Partial Evaluation and Semantics-Based Program Manipulation, San Antonio, Texas, Proceedings, 1999, pp. 119-130.

  5. Correnson, L., Duris, E., Parigot, D., and Roussel, G. Declarative program transformation: A deforestation case-study. In Principles and Practice of Declarative Programming, Paris, France, Proceedings, vol. 1702 of LNCS, 1999, pp. 360-377.

  6. Engelfriet, J. and Vogler, H. Macro tree transducers. J. Comput. Syst. Sci., 31(1) (1985) 71-146.

    Google Scholar 

  7. Fülöp, Z. On attributed tree transducers. Acta Cybernetica, 5 (1981) 261-279.

    Google Scholar 

  8. Gill, A. Cheap deforestation for non-strict functional languages. Ph.D. thesis, University of Glasgow, 1996.

  9. Gill, A., Launchbury, J., and Peyton Jones, S. A short cut to deforestation. In Functional Programming Languages and Computer Architecture, Copenhagen, Denmark, Proceedings, 1993, pp. 223-232.

  10. Hamilton, G. and Jones, S. Extending deforestation for first order functional programs. In 1991 Glasgow Workshop on Functional Programming, Portree, Scotland, Proceedings, 1992, pp. 134-145.

  11. Höff, M., Vater, R., Maletti, A., Kühnemann, A., and Voigtländer, J. Tree transducer based program transformations for Haskell+. Progress report, Dresden University of Technology, 2001. http://wwwtcs.inf.tu-dresden.de/~voigt/hpgreport.ps.gz.

  12. Johann, P. A generalization of short-cut fusion and its correctness proof. Higher-Order and Symb. Comp., 15(4) (2002) 273-300.

    Google Scholar 

  13. Johnsson, T. Attribute grammars as a functional programming paradigm. In Functional Programming Languages and Computer Architecture, Portland, Oregon, Proceedings, vol. 274 of LNCS, 1987, pp. 154-173.

  14. Kakehi, K., Glück, R., and Futamura, Y. On deforesting parameters of accumulating maps. In Logic Based Program Synthesis and Transformation, Paphos, Cyprus, Proceedings, vol. 2372 of LNCS, 2001, pp. 46-56.

  15. Knuth, D. Semantics of context-free languages. Math. Syst. Theory, 2(2) (1968) 127-145. Corrections Ibid., 5(1) (1971) 95-96.

    Google Scholar 

  16. Kühnemann, A. Benefits of tree transducers for optimizing functional programs. In Foundations of Software Technology & Theoretical Computer Science, Chennai, India, Proceedings, vol. 1530 of LNCS, 1998, pp. 146-157.

  17. Kühnemann, A. Comparison of deforestation techniques for functional programs and for tree transducers. In Functional and Logic Programming, Tsukuba, Japan, Proceedings, vol. 1722 of LNCS, 1999, pp. 114-130.

  18. Kuiper, M. and Swierstra, S. Using attribute grammars to derive efficient functional programs. In Computing Science in the Netherlands, Amsterdam, The Netherlands, Proceedings, 1987, pp. 39-52.

  19. Milner, R. A theory of type polymorphism in programming. J. Comput. Syst. Sci., 17(3) (1978) 348-375.

    Google Scholar 

  20. Nishimura, S. Deforesting in accumulating parameters via type-directed transformations. In Asian Workshop on Programming Languages and Systems, Shanghai, China, Proceedings, 2002.

  21. Pettorossi, A. Transformation of programs and use of tupling strategy. In Informatica, Bled, Yugoslavia, Proceedings, 1977, pp. 1-6.

  22. Pettorossi, A. Derivation of programs which traverse their input data only once. In Advanced School on Programming Methodologies, Rome, Italy, Proceedings, 1987, pp. 165-184.

  23. Pettorossi, A. and Proietti, M. Importing and exporting information in program development. In Partial Evaluation and Mixed Computation, Gammel Avernaes, Denmark, Proceedings, 1987, pp. 405-425.

  24. Peyton Jones, S. (Ed.). Haskell 98 Language and Libraries: The Revised Report. Cambridge University Press, 2003.

  25. Peyton Jones, S. and Marlow, S. Secrets of the Glasgow Haskell Compiler inliner. J. Funct. Prog., 12(4/5) (2002) 393-433.

    Google Scholar 

  26. Peyton Jones, S., Partain, W., and Santos, A. Let-floating: Moving bindings to give faster programs. In International Conference on Functional Programming, Philadelphia, Pennsylvania, Proceedings, 1996, pp. 1-12.

  27. Reuther, S. Adding a tree transducer recognition/transformation pass to the Glasgow Haskell Compiler. Students project, Dresden University of Technology, 2002.

  28. Runciman, C., Firth, M., and Jagger, N. Transformation in a non-strict language: An approach to instantiation. In 1989 Glasgow Workshop on Functional Programming, Fraserburgh, Scotland, Proceedings, 1989, pp. 133-141.

  29. Sands, D. Total correctness by local improvement in the transformation of functional programs. ACM Trans. Prog. Lang. Syst., 18(2) (1996) 175-234.

    Google Scholar 

  30. Sørensen, M., Glück, R., and Jones, N. A positive supercompiler. J. Funct. Prog., 6(6) (1996) 811-838.

    Google Scholar 

  31. Svenningsson, J. Shortcut fusion for accumulating parameters & zip-like functions. In International Conference on Functional Programming, Pittsburgh, Pennsylvania, Proceedings, 2002, pp. 124-132.

  32. Swierstra, S. and de Moor, O. Virtual data structures. In Formal Program Development, vol. 755 of LNCS, 1993, pp. 355-371.

  33. van Groningen, J. Optimising recursive functions yielding multiple results in tuples in a lazy functional language. In Implementation of Functional Languages, Lochem, The Netherlands, Proceedings, vol. 1868 of LNCS, 1999, pp. 59-76.

  34. Voigtländer, J. Composition of restricted macro tree transducers. Master's thesis, Dresden University of Technology, 2001. http://wwwtcs.inf.tu-dresden.de/~voigt/mscthesis.ps.gz.

  35. Voigtländer, J. Using circular programs to deforest in accumulating parameters. In Asian Symposium on Partial Evaluation and Semantics-Based Program Manipulation, Aizu, Japan, Proceedings, 2002, pp. 126-137.

  36. Voigtländer, J. and Kühnemann, A. Composition of functions with accumulating parameters. Technical Report TUD-FI01-08, Dresden University of Technology, 2001. http://wwwtcs.inf.tu-dresden.de/~voigt/TUD-FI01-08.ps.gz. Revised version to appear in J. Funct. Prog.

  37. Wadler, P. Deforestation: Transforming programs to eliminate trees. Theor. Comput. Sci., 73(2) (1990) 231-248.

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

About this article

Cite this article

Voigtländer, J. Using Circular Programs to Deforest in Accumulating Parameters. Higher-Order and Symbolic Computation 17, 129–163 (2004). https://doi.org/10.1023/B:LISP.0000029450.36668.cb

Download citation

  • Issue Date:

  • DOI: https://doi.org/10.1023/B:LISP.0000029450.36668.cb

Navigation