[Haskell-cafe] GHC predictability

Andrew Coppin andrewcoppin at btinternet.com
Tue May 13 16:24:05 EDT 2008


Jeff Polakow wrote:

> Then, I immediately blow my stack if I try something like:
>
>     mean [1..1000000000].
>
> The culprit is actually sum which is defined in the base libraries as 
> either a foldl or a direct recursion depending on a compiler flag. In 
> either case, the code is not strict enough; just trying to compute:
>
>      sum [1..10000000]
>
> blows the stack. This can be easily fixed by defining a suitable 
> strict sum:
>
>     sum' = foldl' (+) 0
>
> and now sum' has constant space.

OK *now* I'm worried... I thought sum was _already_ defined this way? o_O



More information about the Haskell-Cafe mailing list