[Haskell-cafe] Is lazyness make big difference?

Nicolas Frisby nicolas.frisby at gmail.com
Thu Feb 15 12:30:12 EST 2007

Someone already mentioned John Hughes paper. Another resource is SPJ's
"hair shirt" slides (also discusses type classes and monads).


Laziness is addressed beginning on slide 19.

Other Nick

On 2/15/07, Nick <nick.linker at rambler.ru> wrote:
>  Hi all,
>  (Another topic stolen from a Russian forum discussion).
>  As everyone know, there are lot of strict languages, that have
> possibilities to "switch on" lazy evaluation when needed.
>  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:
>  main = print primes
> primes = 2:filter is_prime [3,5..]
> is_prime n = all (\p-> n `mod` p /= 0) (takeWhile (\p-> p*p<=n) primes)
>  We can rewrite this in strict languages with lazy constructs. For example,
> in Scala (of course stream is not only lazily evaluated thing there)
> def main(args: Array[String]): Unit = {
>      val n = Integer.parseInt(args(0))
>      System.out.println(primes(ints(2)) take n toList)
>  }
>  def primes(nums: Stream[Int]): Stream[Int] =
>      Stream.cons(nums.head,
>          primes ((nums tail) filter (x => x % nums.head != 0)) )
>  def ints(n: Int): Stream[Int] =
>      Stream.cons(n, ints(n+1))
>  I think the Haskell solution is more compact due to syntactic sugar,
> curring and "parentheses-free-ness", *not* lazy evaluation.
>  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. :-)
>  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?
>  Thank you for the attention.
>  With best regards,
>  Nick.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list