
13 Sep
2012
13 Sep
'12
8:03 p.m.
Yes, because sum is defined in the Report as using foldl. This is silly, but it is what it is. With optimizations on, GHC often converts foldl into foldl' (when it's semantics-preserving) because of this and other functions which "must" use foldl.
I see. This, though, sounds like an argument for scanl' for me, so that I don't have to rely on it doing optimisations like this "often" (in last . scanl, it obviously doesn't), and not to have the usefulness of my library hovering between fast/constant-memory and eats-all-my-ram based on the hope that -O guesses what I want (doesn't work in ghci, of course) *and* that the user knows how I construct my lists internally.