sum and product thunkpile
Do "ulimit -v 524288" at the shell so your machine won't hang. Run ghci, bring in Data.List, and execute "sum [1..10**8]". Notice that you run out of memory. Now try again with "foldl1' (+) [1..10**8]". Note that you get an answer.
The definition of sum and product in the Report use foldl. However, the versions currently being used are open-coded for some reason. They should just use foldl1' (after handling the special case of the empty list appropriately). As it is, the functions thunkpile; this seems pointless, as they are ultimately completely strict in their argument.
This kind of bug is grim for new users, which is why the severity is marked "major".
Patch attached.
Trac metadata
Trac field | Value |
---|---|
Version | 6.9 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | libraries/base |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | Multiple |
Architecture | Multiple |