Is the "where" keyword lazy?

142 Views Asked by At

Assuming I have a function like

foo = 8 + f1
  where f1 = 8 + 9
        f2 = 8 + 10

f1 clearly has to be evaluated, but f2 doesn't have to be. Will it be though? I can see how evaluating every where expression would be a performance issue.

1

There are 1 best solutions below

3
On BEST ANSWER

Yes, it's lazy, so that f2 will not be evaluated, for example:

foo = 8 + f1
    where f1 = 8 + 9
          f2 = last [1..]

will be calculated instantly, and would take forever if it was strict.