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.
Similar content being viewed by others
References
Bird, R. Using circular programs to eliminate multiple traversals of data. Acta Informatica, 21(3) (1984) 239-250.
Burstall, R. and Darlington, J. A transformation system for developing recursive programs. J. ACM, 24(1) (1977) 44-67.
Chin, W. Safe fusion of functional expressions II: Further improvements. J. Funct. Prog., 4(4) (1994) 515-555.
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.
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.
Engelfriet, J. and Vogler, H. Macro tree transducers. J. Comput. Syst. Sci., 31(1) (1985) 71-146.
Fülöp, Z. On attributed tree transducers. Acta Cybernetica, 5 (1981) 261-279.
Gill, A. Cheap deforestation for non-strict functional languages. Ph.D. thesis, University of Glasgow, 1996.
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.
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.
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.
Johann, P. A generalization of short-cut fusion and its correctness proof. Higher-Order and Symb. Comp., 15(4) (2002) 273-300.
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.
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.
Knuth, D. Semantics of context-free languages. Math. Syst. Theory, 2(2) (1968) 127-145. Corrections Ibid., 5(1) (1971) 95-96.
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.
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.
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.
Milner, R. A theory of type polymorphism in programming. J. Comput. Syst. Sci., 17(3) (1978) 348-375.
Nishimura, S. Deforesting in accumulating parameters via type-directed transformations. In Asian Workshop on Programming Languages and Systems, Shanghai, China, Proceedings, 2002.
Pettorossi, A. Transformation of programs and use of tupling strategy. In Informatica, Bled, Yugoslavia, Proceedings, 1977, pp. 1-6.
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.
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.
Peyton Jones, S. (Ed.). Haskell 98 Language and Libraries: The Revised Report. Cambridge University Press, 2003.
Peyton Jones, S. and Marlow, S. Secrets of the Glasgow Haskell Compiler inliner. J. Funct. Prog., 12(4/5) (2002) 393-433.
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.
Reuther, S. Adding a tree transducer recognition/transformation pass to the Glasgow Haskell Compiler. Students project, Dresden University of Technology, 2002.
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.
Sands, D. Total correctness by local improvement in the transformation of functional programs. ACM Trans. Prog. Lang. Syst., 18(2) (1996) 175-234.
Sørensen, M., Glück, R., and Jones, N. A positive supercompiler. J. Funct. Prog., 6(6) (1996) 811-838.
Svenningsson, J. Shortcut fusion for accumulating parameters & zip-like functions. In International Conference on Functional Programming, Pittsburgh, Pennsylvania, Proceedings, 2002, pp. 124-132.
Swierstra, S. and de Moor, O. Virtual data structures. In Formal Program Development, vol. 755 of LNCS, 1993, pp. 355-371.
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.
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.
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.
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.
Wadler, P. Deforestation: Transforming programs to eliminate trees. Theor. Comput. Sci., 73(2) (1990) 231-248.
Author information
Authors and Affiliations
Rights 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
Issue Date:
DOI: https://doi.org/10.1023/B:LISP.0000029450.36668.cb