[Haskell-cafe] Order of Evaluation

Lennart Augustsson lennart at augustsson.net
Fri May 9 17:55:25 EDT 2008

As others have pointed out, there are many allowed evaluation orders of this
But not only that, how it gets evaluated depends on how you are going to use
it.  Say that you print it, then you need all 4 elements, but say that it's
oly going to be used as an argument to null, then you will evaluate less

Even so, it's instructive to study how the normal order reduction of this
expression would proceed under the assumption that all 4 elements will be

  -- Lennart

On Fri, May 9, 2008 at 6:52 PM, PR Stanley <prstanley at ntlworld.com> wrote:

> Hi
>  (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? How would I
> illustrate the evaluation step-by-step?
> I'm guessing that  the code necessitates lazy evaluation and as such it
> starts with take then it applies f which in turn applies s and t and zipWith
> until the first element satisfies the predicate in map and This is repeated
> 4 times
> What does the list think?
> Many thanks,
> Paul
> P.S. I'm not done with induction. I'm just letting it rst for a bit.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080509/c59dfdfd/attachment.htm

More information about the Haskell-Cafe mailing list