« Return to Thread: Order of Evaluation

Re: Order of Evaluation

by Richard Kelsall :: Rate this Message:

Reply to Author | View in Thread

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
unsafePerformIO.

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
question.


Richard.


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

 « Return to Thread: Order of Evaluation