[Haskell-cafe] Order of Evaluation

Richard Kelsall r.kelsall at millstream.com
Fri May 9 14:43:48 EDT 2008

PR Stanley wrote:
>  (take 4 . map (>0)) (f s t)
>  where
>     s = 2 : t
>     t = 3 : s
>  f = zipWith (-)
> What would be the order of evaluation for the above code? 

As I understand it Haskell does not specify an order of evaluation
and it would therefore be a mistake to write a program which relies
on a particular evaluation order. This is the 'unsafe' aspect of

It is entirely at the whim of the compiler writer how it is evaluated
as long as the eventual answer produced is correct. It would be possible
to evaluate it in all sorts of exotic ways, or maybe choose a different
one for each day of the week.

However, you may be asking how does GHC 6.8.2 evaluate it when compiled
at a certain optimisation level so you can make your program run fast
or use less memory. In which case there will be a precise answer to your


More information about the Haskell-Cafe mailing list