The case for laziness
Laziness is required for certain things:
- Avoiding infinite loops/recursion using lazy control flow operations (even strict languages must provide lazy control flow)
- Defining cyclic dependencies - when two pieces of code depend on one another, one's reference to the other must be resolved a bit later. For example if we define a global
true = lib.booleans.true
and false = lib.booleans.false
lazily then even the definitions of lib
, lib.booleans
, lib.booleans.true
, and lib.booleans.false
can use true
and false
. With call-by-need this is OK but it may not terminate in call-by-value or call-by-name scenarios.
- Slot expressions can refer to the object they are a slot on via their "self" binding. They can even refer to slots that are not yet defined - but which must later be defined in order for that slot to be defined at that time. Thus the value and defined-ness of a slot may depend on the value of self and its evaluation should be lazy.