This whole question is relevant only for GHC <7.10. In recent versions, sum [1..1000000] works fine in constant space, at least on built-in number types.
sum implemented with evil foldl 1 , which is not as strict as it should be. So what you get from sum is essentially a bunch of tricks the size of your input. I think there was a discussion about why this is done here at some point ... IMO this is basically just stupid, since the amounts usually cannot be consumed lazily, anyway, it is simply obvious that using strict help .
Prelude>: m + Data.List
Prelude Data.List> foldl '(+) 0 [1..1000000]
500000500000
1 Actually, foldl used only in the report version ... but the explicit recursive version with battery, of course, is not better.
source share