Lazy Evaluation
So far, we have not paid much attention to how Haskell programs are evaluated. Perhaps you have not seen anything out of the ordinary, but then we have really only scratched the surface. When we dig a little deeper, it turns out that Haskell’s evaluation strategy is quite different from that of other languages.
While other languages eagerly evaluate the program, Haskell has a much lazier attitude. Why should it do any work when it’s not clear that work is actually necessary? That’s why Haskell puts off evaluating any part of the program until it becomes clear that no result can be produced without doing that work.
This chapter gives a good idea of how evaluation works and why there is room for different strategies. It briefly covers the most popular evaluation strategy among programming languages, Call by Value, and its opposite, Call by Name. We will learn that neither is ideal and that Haskell’s lazy evaluation strategy combines the...