Maximal Laziness

Eelco Dolstra
2009 Electronical Notes in Theoretical Computer Science  
In lazy functional languages, any variable is evaluated at most once. This paper proposes the notion of maximal laziness, in which syntactically equal terms are evaluated at most once: if two terms e1 and e2 arising during the evaluation of a program have the same abstract syntax representation, then only one will be evaluated, while the other will reuse the former's evaluation result. Maximal laziness can be implemented easily in interpreters for purely functional languages based on term
more » ... ing systems that have the property of maximal sharing -if two terms are equal, they have the same address. It makes it easier to write interpreters, as techniques such as closure updating, which would otherwise be required for efficiency, are not needed. Instead, a straight-forward translation of call-by-name semantic rules yields a call-by-need interpreter, reducing the gap between the language specification and its implementation. Moreover, maximal laziness obviates the need for optimisations such as memoisation and let-floating. Introduction In lazy functional languages such as Haskell [18] , the value of a variable binding is computed only when it is needed, and then only once. For instance, in the Haskell function f x y = if x == 0 then y else z + z where z = product [1..x] the function argument y is only computed when x = 0, and the local variable z only and only once when x = 0. Laziness is a useful property because it allows the programmer to abstract over the ordering of computations, and
doi:10.1016/j.entcs.2009.09.042 fatcat:jms7fe4c7bairikpz64kvuq4ve