Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are the clever uses of strict evaluation?

It seems like there are plenty of examples of clever things being done in a lazily-evaluated language that can't be done in an environment with strict evaluation. For example infinite lists in Haskell or replacing every element in a tree with the tree's minimum value in one pass.

Are there any examples of clever things being done in a strictly-evaluated language that can't easily be done in a lazily-evaluated language?

like image 560
drt Avatar asked Mar 16 '09 17:03

drt


2 Answers

The main things you can do easily in an eager (strict) language and not in a lazy language:

  • Predict from the source code the time and space costs of your programs

  • Permit side effects, including constant-time update of mutable arrays, which makes it easier to implement some algorithms fast

In my opinion, the major benefit of an eager language is that it's much easier to get your code to perform the way you want, and there are very few performance traps in which a small change in the code leads to a huge change in performance.

Having said that, on the whole I prefer to write complicated things in Haskell.

like image 94
Norman Ramsey Avatar answered Oct 03 '22 02:10

Norman Ramsey


No; there are some things you can do* with lazy evaluation (AKA normal-order reduction, or left-outermost reduction) that you can't do with strict evaluation, but not the other way around.

The reason for this is that lazy evaluation is in some way the ‘most general’ way to evaluate, which is known as:

The Computational Adequacy Theorem: If some order of evaluation terminates and produces a particular result, then lazy evaluation will also terminate and produce the same result.

* (please note that we are not talking about Turing-equivalence here)

like image 30
porges Avatar answered Oct 03 '22 04:10

porges