Skip to main content
Log in

Call-by-need and continuation-passing style

  • Published:
LISP and Symbolic Computation

Abstract

This paper examines the transformation of call-by-need λ terms into continuation-passing style (CPS). It begins by presenting a simple transformation of call-by-need λ terms into program graphs and a reducer for such graphs. From this, an informal derivation is carried out, resulting in a translation from λ terms into self-reducing program graphs, where the graphs are represented as CPS terms involving storage operations. Though informal, the derivation proceeds in simple steps, and the resulting translation is taken to be our canonical CPS transformation for call-by-need λ terms.

In order to define the CPS transformation more formally, two alternative presentations are given. The first takes the form of a continuation semantics for the call-by-need language. The second presentation follows Danvy and Hatcliff's two-stage decomposition of the call-by-name CPS transformation, resulting in a similar two-stage CPS transformation for call-by-need.

Finally, a number of practical matters are considered, including an improvement to eliminate the so-called administrative redexes, as well as to avoid unnecessary memoization and take advantage of strictness information. These improvements make it feasible to consider potential applications in compilers for call-by-need programming languages.

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. Appel, Andrew W. and Jim, Trevor. Continuation-passing, closure-passing style. InSixteenth ACM Symposium on Principles of Programming Languages (1989) 293–302.

  2. Asperti, Andrea. Integrating strict and lazy evaluation: the λ sl -calculus. In Deransart, P. and Maluszyński, J., editors,Programming Language Implementation and Logic Programming, Sweden, Springer-Verlag (1990) 238–254.

  3. Augusteijn, A. and van der Hoeven, G. Combinatorgraphs as self-reducing programs. (1984). Unpublished workshop presentation.

  4. Augustsson, Lennart.Compiling Lazy Functional Languages, Part II. PhD thesis, Department of Computer Sciences, Chalmers University of Technology (1987).

  5. Bloss, Adrienne, Hudak, Paul, and Young, Jonathan. Code optimizations for lazy evaluation.Lisp and Symbolic Computation, 1 (1988) 147–164.

    Google Scholar 

  6. Burn, Geoffrey L., Hankin, Chris, and Abramsky, Samson. Strictness analysis of higher-order functions.Science of Computer Programming, 7 (1986) 249–278.

    Google Scholar 

  7. Burn, Geoffrey L., Peyton Jones, Simon L., and Robson, John D. The Spineless G-Machine. InProceedings of the ACM Conference on Lisp and Functional Programming, Snowbird (1988) 244–258.

  8. Danvy, Olivier and Filinski, Andrzej. Representing control, a study of the CPS transformation.Mathematical Structures in Computer Science, 2, 4 (December 1992) 361–391.

    Google Scholar 

  9. Danvy, Olivier and Hatcliff, John. Thunks (continued). InProceedings of the Workshop on Static Analysis WSA '92, IRISA, Rennes, France, Bordeaux, France (September 1992) 3–11. Extended version available as Technical Report CIS-92-28, Kansas State University.

  10. Danvy, Olivier and Hatcliff, John. CPS transformation after strictness analysis.ACM Letters on Programming Languages and Systems, 1, 3 (1993). To appear.

  11. Futamura, Yoshihito. Partial evaluation of computation process — an approach to a compiler-compiler.Systems, Computers, Controls, 2, 5 (1971) 45–50.

    Google Scholar 

  12. Goldberg, Benjamin. Detecting sharing of partial applications in functional programs. In Kahn, Gilles, editor,Proceedings of the Conference on Functional Programming and Computer Architecture, Portland, Springer-Verlag (1987) 408–425.

  13. Hughes, John.The Design and Implementation of Programming Languages. PhD thesis, Oxford University (1983).

  14. Johnsson, Thomas. Lambda lifting: transforming programs to recursive equations. In Jouannaud, J.-P., editor,Conference on Functional Programming Languages and Computer Architecture, Nancy, Springer-Verlag (September 1985) 190–203.

  15. Johnsson, Thomas.Compiling Lazy Functional Languages. PhD thesis, Department of Computer Sciences, Chalmers University of Technology (1987).

  16. Jørgensen, Jesper. Generating a compiler for a lazy language by partial evaluation. InSymposium on Principles of Programming Languages (January 1992) 258–268.

  17. Josephs, Mark B. The semantics of lazy functional languages.Theoretical Computer Science, 68 (1989) 105–111.

    Google Scholar 

  18. Koopman, Philip J., Lee, Peter, and Siewiorek, Daniel. Cache behavior of combinator graph reduction.ACM Transactions on Programming Languages and Systems, 14, 2 (April 1992) 265–297.

    Google Scholar 

  19. Kranz, David, Kelsey, Richard, Rees, Jonathan, Hudak, Paul, Philbin, James, and Adams, Norman. Orbit: An optimizing compiler for Scheme. InProceedings of the SIGPLAN '86 Symposium on Compiler Construction (July 1986) 219–233.

  20. Mycroft, Alan. The theory and practice of transforming call-by-need into call-by-value. InProceedings of the 4th International Symposium on Programming, Springer-Verlag (1980) 269–281.

  21. Nielson, Flemming and Nielson, Hanne Riis. Two-level semantics and code generation.Theoretical Computer Science, 56, 1 (January 1988) 59–133.

    Google Scholar 

  22. Peyton Jones, Simon L. Implementing lazy functional languages on stock hardware: the Spineless Tagless G-machine.Journal of Functional Programming, 2, 2 (April 1992) 127–202.

    Google Scholar 

  23. Plotkin, Gordon D. Call-by-name, call-by-value and the λ-calculus.Theoretical Computer Science, 1 (1975) 125–159.

    Google Scholar 

  24. Reynolds, John C. Definitional interpreters for higher-order programming languages. InProceedings of the ACM National Conference, New York, New York (1972) 717–740.

  25. Steele Jr., Guy L.Rabbit: a compiler for Scheme. Technical Report AITR-474, MIT (1978).

  26. Turner, David A. A new implementation technique for applicative languages.Software — Practice and Experience, 9, 1 (January 1979) 31–49.

    Google Scholar 

  27. Wadsworth, Christopher P.Semantics and Pragmatics of The Lambda Calculus. PhD thesis, University of Oxford (1971).

  28. Wand, Mitchell. A short proof of the lexical addressing algorithm.Information Processing Letters, 35 (1990) 1–5.

    Google Scholar 

  29. Wand, Mitchell. Specifying the correctness of binding-time analysis. InSymposium on Principles of Programming Languages (January 1993) 137–143.

  30. Wang, Ching-lin. Obtaining lazy evaluation with continuations in Scheme.Information Processing Letters, 35 (1990) 93–97.

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Additional information

Supported in part by the National Science Foundation under PYI grant #CCR-9057567, with matching funds from Bell Northern Research.

Supported by an AT&T Ph.D. scholarship.

Rights and permissions

Reprints and permissions

About this article

Cite this article

Okasaki, C., Lee, P. & Tarditi, D. Call-by-need and continuation-passing style. LISP and Symbolic Computation 7, 57–81 (1994). https://doi.org/10.1007/BF01019945

Download citation

  • Issue Date:

  • DOI: https://doi.org/10.1007/BF01019945

Keywords

Navigation