#2622: sum and product thunkpile
----------------------------+-----------------------------------------------
Reporter: Bart Massey | Owner:
Type: bug | Status: new
Priority: normal | Component: libraries/base
Version: 6.9 | Severity: major
Keywords: | Testcase:
Architecture: Multiple | Os: Multiple
----------------------------+-----------------------------------------------
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. This is just a context unidiff against current Darcs
head; a Darcs-format patch with full context (at 350KB) is at
http://po8.org/bart/sumprod.patch
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2622>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs