Evaluation strategies
Before we delve into Haskell’s evaluation strategy, let us first consider what an evaluation strategy is. This is an aspect of a programming language that is usually not questioned or mentioned because most languages adopt the same strategy and act alike. This section shows that there is room for variation and that there are good reasons for deviating from the mainstream strategy.
Beta reduction
The mechanism at the core of program evaluation in function programming is called beta reduction. It defines how a function call should be evaluated. Let us take a small example of a function call (also called a function application):
(\ x -> sin x) 1.0
Here the (anonymous) (\ x -> sin x)
function maps its formal parameter x
to the function body sin x
. This function is applied to the actual parameter 1.0
.
Conceptually, the function call is evaluated, or reduced, by replacing it with a simpler expression. That simpler expression is the function...