[Haskell-cafe] How is laziness defined?

Donald Bruce Stewart dons at cse.unsw.edu.au
Mon Feb 5 01:17:02 EST 2007

> On 2/5/07, ajb at spamcop.net <ajb at spamcop.net> wrote:
> >Quoting TJ <tjay.dreaming at gmail.com>:
> >
> >> I would think that with 100% laziness, nothing would happen until the
> >> Haskell program needed to output data to, e.g. the console. Quite
> >> obviously that's not it. So how is laziness defined in Haskell?
> >
> >It means that the program behaves as if "things" are evaluated if and
> >only if they are needed.  "Needed" in the Haskell sense, means "needed
> >to do I/O".
> So it's just IO which makes things run huh? OK that's basically what I
> said there. Cool.

Exactly, no IO, no computation required:

    $ cat A.hs
    main = do
        let v = last [1..] -- could be very slow...
        return ()

    $ time ./a.out
    ./a.out  0.00s user 0.00s system 0% cpu 0.003 total


Laziness: you know it makes sense.

-- Don

More information about the Haskell-Cafe mailing list