The call-by-need lambda calculus provides an equational framework for reasoning syntactically about lazy evaluation. This paper examines its operational characteristics. By a series of reasoning steps, we systematically unpack the standard-order reduction relation of the calculus and discover a novel abstract machine definition which, like the calculus, goes "under lambdas." We prove that machine evaluation is equivalent to standard-order evaluation. Unlike traditional abstract machines, delimited control plays a significant role in the machine's behavior. In particular, the machine replaces the manipulation of a heap using store-based effects with disciplined management of the evaluation stack using control-based effects. In short, state is replaced with control. To further articulate this observation, we present a simulation of call-by-need in a call-by-value language using delimited control operations.
Deep Dive into Lazy Evaluation and Delimited Control.
The call-by-need lambda calculus provides an equational framework for reasoning syntactically about lazy evaluation. This paper examines its operational characteristics. By a series of reasoning steps, we systematically unpack the standard-order reduction relation of the calculus and discover a novel abstract machine definition which, like the calculus, goes “under lambdas.” We prove that machine evaluation is equivalent to standard-order evaluation. Unlike traditional abstract machines, delimited control plays a significant role in the machine’s behavior. In particular, the machine replaces the manipulation of a heap using store-based effects with disciplined management of the evaluation stack using control-based effects. In short, state is replaced with control. To further articulate this observation, we present a simulation of call-by-need in a call-by-value language using delimited control operations.
Logical Methods in Computer Science
Vol. 6 (3:1) 2010, pp. 1–37
www.lmcs-online.org
Submitted
Oct. 12, 2009
Published
Jul. 11, 2010
LAZY EVALUATION AND DELIMITED CONTROL
RONALD GARCIA a, ANDREW LUMSDAINE b, AND AMR SABRY c
a Carnegie Mellon University
e-mail address: rxg@cs.cmu.edu
b,c Indiana University
e-mail address: {lums,sabry}@cs.indiana.edu
Abstract. The call-by-need lambda calculus provides an equational framework for rea-
soning syntactically about lazy evaluation. This paper examines its operational character-
istics.
By a series of reasoning steps, we systematically unpack the standard-order reduc-
tion relation of the calculus and discover a novel abstract machine definition which, like
the calculus, goes “under lambdas.” We prove that machine evaluation is equivalent to
standard-order evaluation.
Unlike traditional abstract machines, delimited control plays a significant role in the
machine’s behavior. In particular, the machine replaces the manipulation of a heap using
store-based effects with disciplined management of the evaluation stack using control-based
effects. In short, state is replaced with control.
To further articulate this observation, we present a simulation of call-by-need in a call-
by-value language using delimited control operations.
1. Introduction
From early on, the connections between lazy evaluation (Friedman and Wise, 1976;
Henderson and Morris, 1976) and control operations seemed strong. One of these seminal
papers on lazy evaluation (Henderson and Morris, 1976) advocates laziness for its coroutine-
like behavior. Specifically, it motivates lazy evaluation with a solution to the same fringe
problem: how to determine if two trees share the same fringe without first flattening each
tree and then comparing the resulting lists. A successful solution to the problem traverses
just enough of the two trees to tell that they do not match.
The same fringe problem
is also addressed in Sussman and Steele’s original exposition of the Scheme programming
1998 ACM Subject Classification: D.3.1.
Key words and phrases: call-by-need, reduction semantics, abstract machines, delimited continuations,
lambda calculus.
a This work was supported by the National Science Foundation under Grant #0937060 to the Computing
Research Association for the CIFellows Project.
b,c This work was supported by NSF awards CSR/EHS 0720857 and CCF 0702717.
LOGICAL METHODS
l IN COMPUTER SCIENCE
DOI:10.2168/LMCS-6 (3:1) 2010
c
⃝
R. Garcia, A. Lumsdaine, and A. Sabry
CC
⃝
Creative Commons
2
R. GARCIA, A. LUMSDAINE, AND A. SABRY
language (Sussman and Steele Jr., 1975). One of their solutions uses a continuation passing-
style representation of coroutines. More recently, Biernacki et al. (2005) explores a number
of continuation-based solutions to same fringe variants.
Same fringe is not the only programming problem that can be solved using either lazy
evaluation or continuations. For instance, lazy streams and continuations are also used to
implement and reason about backtracking (Wand and Vaillancourt, 2004; Kiselyov et al.,
2005). Strong parallels in the literature have long suggested that lazy evaluation elegantly
embodies a stylized use of coroutines. Indeed, we formalize this connection.
Call-by-need evaluation combines the equational reasoning capabilities of call-by-name
with a more efficient implementation technology that systematically shares the results of
some computations. However, call-by-need’s evaluation strategy makes it difficult to reason
about the operational behavior and space usage of programs. In particular, call-by-need
evaluation obscures the control flow of evaluation. To facilitate reasoning, semantic mod-
els (Launchbury, 1993; Sestoft, 1997; Friedman et al., 2007; Nakata and Hasegawa, 2009),
simulations (Okasaki et al., 1994), and tracing tools (Gibbons and Wansbrough, 1996) for
call-by-need evaluation have been developed. Many of these artifacts use an explicit store
or store-based side-effects (Wang, 1990) to represent values that are shared between parts
of a program. Stores, being amorphous structures, make it difficult to establish program
properties or analyze program execution. This representation of program execution loses
information about the control structure of evaluation.
The call-by-need lambda calculus was introduced by Ariola et al. (1995) as an alter-
native to store-based formalizations of lazy evaluation. It is an equational framework for
reasoning about call-by-need programs and languages. Following Plotkin (1975), these au-
thors present a calculus and prove a standardization theorem that links the calculus to a
complete and deterministic (i.e. standard order) reduction strategy. The calculus can be
used to formally justify transformations, particularly compiler optimizations, because any
terms it proves equal are also contextually equivalent under call-by-need evaluation.
Call-by-need calculi were investigated by two groups (Maraist et al., 1998; Ariola and Felleisen,
1997). The resul
…(Full text truncated)…
This content is AI-processed based on ArXiv data.