Lazy Evaluation
Let's discuss the evaluation strategy of Haskell, called lazy evaluation.
We'll cover the following...
Evaluation order and termination
Previously, we saw that the order of evaluation does not influence the result of expressions. This changes, however, when non-termination comes into play.
As an example, let’s revisit once more our function both
, the reimplementation of the conjunctive boolean &&
operator:
Press + to interact
both :: Bool -> Bool -> Boolboth False _ = Falseboth True b = bmain = doprint (both True True)print (both False True)
The function both
is implemented by pattern matching on the first argument. If the first argument is already False
, we know that the result is False
and do not need to check the second argument. If the first argument is True
, we do ...