A synthetic operational account of call-by-need evaluation

We present the first operational account of call by need that connects syntactic theory and implementation practice. Syntactic theory: the storeless operational semantics using syntax rewriting to account for demand-driven computation and for caching intermediate results. Implementational practice: the store-based operational technique using memo-thunks to implement demand-driven computation and to cache intermediate results for subsequent sharing. The implementational practice was initiated by Landin and Wadsworth and is prevalent today to implement lazy programming languages such as Haskell. The syntactic theory was initiated by Ariola, Felleisen, Maraist, Odersky and Wadler and is prevalent today to reason equationally about lazy programs, on par with Barendregt et al.'s term graphs. Nobody knows, however, how the theory of call by need compares to the practice of call by need: all that is known is that the theory of call by need agrees with the theory of call by name, and that the practice of call by need optimizes the practice of call by name. Our operational account takes the form of three new calculi for lazy evaluation of lambda-terms and our synthesis takes the form of three lock-step equivalences. The first calculus is a hereditarily compressed variant of Ariola et al.'s call-by-need lambda-calculus and makes "neededness" syntactically explicit. The second calculus distinguishes between strict bindings (which are induced by demand-driven computation) and non-strict bindings (which are used for caching intermediate results). The third calculus uses memo-thunks and an algebraic store. The first calculus syntactically corresponds to a storeless abstract machine, the second to an abstract machine with local stores, and the third to a lazy Krivine machine, i.e., a traditional store-based abstract machine implementing lazy evaluation. The machines are intensionally compatible with extensional reasoning about lazy programs and they are lock-step equivalent. Each machine functionally corresponds to a natural semantics for call by need in the style of Launchbury, though for non-preprocessed λ-terms. Our results reveal a genuine and principled unity of computational theory and computational practice, one that readily applies to variations on the general theme of call by need.

[1]  Olivier Danvy,et al.  From Interpreter to Compiler and Virtual Machine: A Functional Derivation , 2003 .

[2]  Matthias Felleisen,et al.  The call-by-need lambda calculus , 1997, Journal of Functional Programming.

[3]  Olivier Danvy,et al.  On inter-deriving small-step and big-step semantics: A case study for storeless call-by-need evaluation , 2012, Theor. Comput. Sci..

[4]  Olivier Danvy From Reduction-Based to Reduction-Free Normalization , 2008, Advanced Functional Programming.

[5]  Matthias Felleisen,et al.  The Call-by-need Lambda Calculus, Revisited , 2012, ESOP.

[6]  Pierre Crégut,et al.  Strongly reducing variants of the Krivine abstract machine , 2007, High. Order Symb. Comput..

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

[8]  Alexis Saurin,et al.  Classical Call-by-Need and Duality , 2011, TLCA.

[9]  Matthias Felleisen,et al.  Semantics Engineering with PLT Redex , 2009 .

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

[11]  Jean-Louis Krivine,et al.  A call-by-name lambda-calculus machine , 2007, High. Order Symb. Comput..

[12]  Matthias Felleisen,et al.  Evaluating Call-by-Need on the Control Stack , 2010, Trends in Functional Programming.

[13]  Robin Milner,et al.  Communication and concurrency , 1989, PHI Series in computer science.

[14]  Masahito Hasegawa,et al.  Small-step and big-step semantics for call-by-need , 2009, J. Funct. Program..

[15]  Olivier Danvy,et al.  A Functional Correspondence between Evaluators and Abstract Machines , 2003 .

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

[17]  Olivier Danvy,et al.  A syntactic correspondence between context-sensitive calculi and abstract machines , 2005, Theor. Comput. Sci..

[18]  Lasse R. Nielsen,et al.  Refocusing in Reduction Semantics , 2004 .

[19]  Peter Sestoft,et al.  Deriving a lazy abstract machine , 1997, Journal of Functional Programming.

[20]  Marko C. J. D. van Eekelen,et al.  Term Graph Rewriting , 1987, PARLE.

[21]  Dariusz Biernacki,et al.  Automating Derivations of Abstract Machines from Reduction Semantics: - A Generic Formalization of Refocusing in Coq , 2010, IFL.

[22]  Olivier Danvy,et al.  A concrete framework for environment machines , 2005, TOCL.

[23]  Thérèse Hardin,et al.  Functional runtime systems within the lambda-sigma calculus , 1998, Journal of Functional Programming.

[24]  Olivier Danvy,et al.  A functional correspondence between call-by-need evaluators and lazy abstract machines , 2003, Inf. Process. Lett..

[25]  Isao Sasano,et al.  Lightweight fusion by fixed point promotion , 2007, POPL '07.

[26]  Pieter H. Hartel,et al.  Abstract machines for programming language implementation , 2000, Future Gener. Comput. Syst..

[27]  Rémi Douence,et al.  A systematic study of functional language implementations , 1998, TOPL.

[28]  Peter Henderson,et al.  A lazy evaluator , 1976, POPL.

[29]  David A. Schmidt,et al.  Stackability in the Simply-Typed Call-by-Value lambda Calculus , 1998, Sci. Comput. Program..

[30]  Alexis Saurin,et al.  Classical Call-by-Need Sequent Calculi: The Unity of Semantic Artifacts , 2012, FLOPS.

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

[32]  Amr Sabry,et al.  Lazy evaluation and delimited control , 2009, POPL '09.

[33]  Daniel P. Friedman,et al.  Improving the lazy Krivine machine , 2007, High. Order Symb. Comput..

[34]  Matthias Felleisen,et al.  A call-by-need lambda calculus , 1995, POPL '95.

[35]  Olivier Danvy,et al.  Three Syntactic Theories for Combinatory Graph Reduction , 2010, LOPSTR.

[36]  John Launchbury,et al.  A natural semantics for lazy evaluation , 1993, POPL '93.

[37]  Dariusz Biernacki,et al.  A systematic derivation of the STG machine verified in Coq , 2010, Haskell '10.

[38]  Olivier Danvy,et al.  On the Equivalence between Small-Step and Big-Step Abstract Machines: A Simple Application of Lightweight Fusion , 2007 .

[39]  Daniel P. Friedman,et al.  CONS Should Not Evaluate its Arguments , 1976, ICALP.

[40]  John C. Reynolds,et al.  Definitional Interpreters Revisited , 1998, High. Order Symb. Comput..

[41]  Jon Fairbairn,et al.  TIM: A simple, lazy abstract machine to execute supercombinatorics , 1987, FPCA.

[42]  Thibaut Balabonski,et al.  A unified approach to fully lazy sharing , 2012, POPL '12.