
Translated a bit: With lazy evaluation, the order of evaluation is irrelevant as far as the _correctness_ of the function is concerned. However, it's much easier to reason about the _efficiency_ of functions when the language uses strict evaluation; you never have to scratch your head and ask "I wonder under what circumstances will that bit of code get executed, and what will that do to the average running time of this function?" Lazy evaluation does make some kinds of idioms possible that are much harder to do with strict evaluation. For instance, here is an infinite list of ones: let ones = 1 : ones and here is an infinite list of integers: let ints = 1 : map (1+) ints Defining these doesn't cause the language to go into an infinite loop, because the contents of these lists aren't generated until they're needed. Similarly, it's easy to define an infinite list of e.g. prime numbers. Ocaml has a "lazy" module that makes it possible to do things like this, but it's much more cumbersome. Another (non-obvious) "benefit" of having lazy evaluation is that it forces the language to be purely functional. Lazy evaluation doesn't play well with side effects. Mike
Date: Tue, 3 May 2005 21:04:46 -0700 From: Andrew Pimlott
On Wed, May 04, 2005 at 12:40:13PM +1000, Erik de Castro Lopo wrote:
That leaves one aspect of Haskell vs Ocaml I don't yet understand. What are the advantages of lazy evaluation?
The advantage of lazy evaluation is that evaluation order becomes one less thing you have to think about. The disadvantage of lazy evaluation is that evaluation order becomes one more thing you have to think about.
Andrew _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe