# if (++) were left associative ?

**Jon Fairbairn
**
Jon.Fairbairn@cl.cam.ac.uk

*Sun, 07 Apr 2002 17:50:16 +0100*

>* Thanks,
*>* =
*
>* but you are assuming that foldl evaluates the intermediate result right=
*
>* away.
*
It must
>* My understanding of foldl is thus:
*>* =
*
>* foldl (++) [] [[1],[2],[3],[4]]
*
[snip]
>* -> [] ++ [1] ++ [2] ++ [3] ++ [4]
*>* =
*
>* Which brings me back to my original question...
*
Well, you've removed the parentheses that give you the
information you want.
foldl (++) [] [[1],[2],[3],[4]]
-> foldl (++) ([] ++ [1]) [[2],[3],[4]]
-> foldl (++) (([] ++ [1]) ++ [2]) [[3],[4]]
-> foldl (++) ((([] ++ [1]) ++ [2]) ++ [3]) [[4]]
-> foldl (++) (((([] ++ [1]) ++ [2]) ++ [3]) ++ [4]) []
-> (((([] ++ [1]) ++ [2]) ++ [3]) ++ [4])
now you have to ask what has to be evaluated in order to get
the head of the result.
The answer is that you have to evaluate ((([] ++ [1]) ++
[2]) ++ [3]) before you can find it, and to get that, you
have to evaluate (([] ++ [1]) ++ [2]) and so on.
In the other case, you can get the head of (a:...)++ (b ++
c) by evaluating only the first steps of the first (++).
Does that help?
J=F3n
-- =
J=F3n Fairbairn Jon.Fairbairn@cl.cam.ac.u=
k
31 Chalmers Road jf@cl.cam.ac.uk
Cambridge CB1 3SZ +44 1223 570179 (after 14:00 only, please!)