[Haskell-cafe] Re: help understanding lazy evaluation

Jon Fairbairn jon.fairbairn at cl.cam.ac.uk
Thu Aug 23 05:33:39 EDT 2007


Stefan O'Rear <stefanor at cox.net> writes:
> Indeed, you've caught on an important technical distinction.
> 
> Lazy:  Always evaluating left-outermost-first.

I think most people would rather use the term "normal order¨
for that; lazy means evaluating in normal order /and/ not
evaluating the same expression twice.

normal order:
 (\a -> a + a) (2+2)
=> (2+2) + (2+2)
=> 4 + (2+2)
=> 4 + 4
=> 8

lazy:
 (\a -> a + a) (2+2)
=> (2+2) + (2+2)  -- but we still know that both these (2+2)s are the same
=> 4 + 4
=> 8

That might be slightly confusing because I've used (+),
which is strict.  It might have been better to use Ss and
Ks, but less succinct...

> Non-strict: Behaving as if it were lazy.

non-strict: giving the same answers as if it were normal
order.

A haskell implementation could, in principle, conform to the
non-strict requirement without doing any of the update in
place that makes laziness.

> Haskell's semantics are non-strict in nature, but there is no
> requirement for laziness.  All optimizing haskell compilers are
> non-lazy.

????

-- 
Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk




More information about the Haskell-Cafe mailing list