[Haskell-cafe] Re: Lazy evaluation from "Why Functional programming matters"

Ertugrul Soeylemez es at ertes.de
Tue Oct 5 11:19:15 EDT 2010


C K Kashyap <ckkashyap at gmail.com> wrote:

> > Yes. It would slightly easier in, say,  C# or C++.
> > I think 'D' achieves its implementation of the 'lazy' keyword using
> > a similar approach.
> > But I did not understand why you are disappointed ?
>
> The disappointment was not on a serious note ... the thing is, I
> constantly run into discussions about "why fp" with my colleagues - in
> a few of such discussions, I had mentioned that Haskell is the only
> well known language with lazy evaluation (IIRC, I read it somewhere or
> heard it in one of the videos)
>
> And I had built up this impression that laziness distinguished Haskell
> by a huge margin ... but it seems that is not the case.
> Hence the disappointment.

Don't be disappointed.  There are some things, which are extremely
elegant to express with laziness:

  isPrime :: Integral a => a -> Bool
  isPrime n =
    all (\x -> mod n x /= 0) . takeWhile (\x -> x*x <= n) $ primes

  primes :: Integral a => [a]
  primes = 2 : filter isPrime [3..]

These two definitions use each other in a way, which is very difficult
to express without lazy evaluation.


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/




More information about the Haskell-Cafe mailing list