Lazy Evaluation
Explore lazy evaluation in Haskell and understand how it differs from strict evaluation. Learn how Haskell evaluates function arguments only when needed, enabling termination in cases where strict evaluation would not. This lesson helps you grasp evaluation order effects, pattern matching with non-terminating expressions, and implement lazy function versions for better control.
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:
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 ...