Call-by-need and continuation-passing style

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.

[1]  Simon L. Peyton Jones,et al.  The spineless tagless G-machine , 1989, FPCA.

[2]  Flemming Nielson,et al.  Two-Level Semantics and Code Generation , 1988, Theor. Comput. Sci..

[3]  Olivier Danvy,et al.  Representing Control: a Study of the CPS Transformation , 1992, Mathematical Structures in Computer Science.

[4]  Jesper Jørgensen,et al.  Generating a compiler for a lazy language by partial evaluation , 1992, POPL '92.

[5]  Paul Hudak,et al.  Code optimizations for lazy evaluation , 1988, LISP Symb. Comput..

[6]  Simon L. Peyton Jones,et al.  Implementing lazy functional languages on stock hardware: the Spineless Tagless G-machine , 1992, Journal of Functional Programming.

[7]  Benjamin Goldberg,et al.  Detecting sharing of partial applications in functional programs , 1987, FPCA.

[8]  Jr. Guy L. Steele,et al.  Rabbit: A Compiler for Scheme , 1978 .

[9]  Andrea Asperti Integrating Strict and Lazy Evaluation: The lambda-sl-Calculus , 1990, PLILP.

[10]  Ching-Lin Wang Obtaining Lazy Evaluation with Continuations in Scheme , 1990, Inf. Process. Lett..

[11]  Olivier Danvy,et al.  CPS-transformation after strictness analysis , 1992, LOPL.

[12]  Chris Hankin,et al.  Strictness Analysis for Higher-Order Functions , 1986, Sci. Comput. Program..

[13]  Paul Hudak,et al.  ORBIT: an optimizing compiler for scheme , 1986, SIGPLAN '86.

[14]  Simon L. Peyton Jones,et al.  The spineless G-machine , 1988, LISP and Functional Programming.

[15]  D. A. Turner,et al.  A new implementation technique for applicative languages , 1979, Softw. Pract. Exp..

[16]  Mark B. Josephs,et al.  The Semantics of Lazy Functional Languages , 1989, Theor. Comput. Sci..

[17]  Olivier Danvy,et al.  Thunks (Continued) , 1992, WSA.

[18]  Mitchell Wand,et al.  A Short Proof of the Lexical Addressing Algorithm , 1990, Inf. Process. Lett..

[19]  Gordon D. Plotkin,et al.  Call-by-Name, Call-by-Value and the lambda-Calculus , 1975, Theor. Comput. Sci..

[20]  Andrew W. Appel,et al.  Continuation-passing, closure-passing style , 1989, POPL '89.

[21]  Peter Lee,et al.  Cache behavior of combinator graph reduction , 1992, TOPL.

[22]  R. J. M. Hughes,et al.  Design and Implementation of Programming Languages , 1977, Lecture Notes in Computer Science.

[23]  Thomas Johnsson,et al.  Lambda Lifting: Treansforming Programs to Recursive Equations , 1985, FPCA.

[24]  Mitchell Wand,et al.  Specifying the correctness of binding-time analysis , 1993, POPL '93.

[25]  John H. Williams,et al.  Design and Implementation of Programming Languages , 1977 .

[26]  John C. Reynolds,et al.  Definitional Interpreters for Higher-Order Programming Languages , 1972, ACM '72.

[27]  Alan Mycroft,et al.  The Theory and Practice of Transforming Call-by-need into Call-by-value , 1980, Symposium on Programming.