[Prev][Next][Index][Thread]
Call-by-value (eager) vs. Call-by-name (lazy)
May I offer a heretical view of why call-by-value is so often preferred?
Proponents of lazy evaluation are always saying it is more
mathematical; that the mathematical function say f(x)=x+1 means f(x)
can be replaced by x+1 regardless of what x is. However, no
mathematician would replace f(1/0) by 1/0+1 or indeed f(a)+g(b) by
a)+g(b+1. If call-by-name makes mathematical reasoning easier, then
why are there only strict functions in ordinary mathematics? For
instance, why do the Peano axioms define Suc as a strict function?
Call-by-value follows mathematical tradition, while call-by-name
follows the lambda-calculus and the formalist tradition. Curry did not
believe in values at all, only symbols, and the jargon of lazy
evalution ("weak head normal form" etc.) continues this mechanistic
view. It is no wonder that newcomers to lazy functional programming
encounter so many problems.
I would not write off lazy evaluation, which is an extremely powerful
new technology. However it must be understood semantically -- through
domain theory -- not through mechanistic reduction rules. Domain theory
explains why lazy evaluation is a useful notion for computable
functions, but not for functions in general. The semantics of
nontermination explains why f(E) can be replaced by E+1 regardless of
whether E terminates. Note that "E fails to terminate" says a lot more
than "the value of E is undefined".
Regarding theoretical foundations, a great deal of functional programming can
be explained with nothing more than sets and well-founded
recursion/induction. Domains are not needed until non-well-founded
recursion is introduced.
Larry Paulson