I played with Haskell and ghci when I found this, which really bothered me:
foldl (++) [[3,4,5], [2,3,4], [2,1,1]] []
I expected to get the following: [3,4,5,2,3,4,2,1,1] However, it gets:
[[3,4,5],[2,3,4],[2,1,1]]
As far as I understand foldl, it should be like this:
(([] ++ [3, 4, 5]) ++ [2, 3, 4]) ++ [2, 1, 1]
If I find it in ghci, it really is [3,4,5,2,3,4,2,1,1] .
And one more strange thing:
Prelude> foldl1 (++) [[3,4,5], [2, 3, 4], [2, 1, 1]] [3,4,5,2,3,4,2,1,1]
I expect foldl and foldl1 to behave the same. So what does foldl really do?