<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#cccccc" text="#000000">
Hi all,<br>
<br>
(Another topic stolen from a Russian forum discussion).<br>
<br>
As everyone know, there are lot of strict languages,
that have possibilities to "switch on" lazy evaluation when needed.<br>
<br>
But the examples that I saw on Haskell, there was not much use of lazy
evaluation, often there were just several lazy points, and the rest
could be done strictly without loss of generality. For example, in
finding primes:<br>
<blockquote>
  <pre>main        = print primes
primes      = 2:filter is_prime [3,5..]
is_prime n  = all (\p-&gt; n `mod` p /= 0) (takeWhile (\p-&gt; p*p&lt;=n) primes)</pre>
</blockquote>
We can rewrite this in strict languages with lazy constructs. For
example, in Scala (of course stream is not only lazily evaluated thing
there)
<blockquote><tt>def main(args: Array[String]): Unit = {<br>
    val n = Integer.parseInt(args(0))<br>
    System.out.println(primes(ints(2)) take n toList)<br>
}</tt><tt><br>
  <br>
def primes(nums: Stream[Int]): Stream[Int] =<br>
    Stream.cons(nums.head,<br>
        primes ((nums tail) filter (x =&gt; x % nums.head != 0)) )<br>
  <br>
  </tt><tt>def ints(n: Int): Stream[Int] =<br>
    Stream.cons(n, ints(n+1))</tt><br>
</blockquote>
<blockquote><tt> </tt></blockquote>
I think the Haskell solution is more compact due to syntactic sugar,
curring and "parentheses-free-ness", *not* lazy evaluation.<br>
<br>
According to one guy's analogy: the Real World is strict - in order to
drink tea, you have to put the cattle on the fire, wait until water
boils, brew tea and then drink. Not the cattle is put on the fire,
water boils and the tea is brewed when you take the empty cup to start
drinking. :-)<br>
<br>
The question is the following: how big the gap between strict languages
with lazy constructs and Haskell? Does the default lazyness have
irrefutable advantage over default strictness?<br>
<br>
Thank you for the attention.<br>
<br>
With best regards,<br>
Nick.<tt><br>
</tt>
</body>
</html>