[Haskell-cafe] curious about sum

Henning Thielemann lemming at henning-thielemann.de
Tue Jun 16 07:18:33 EDT 2009

On Mon, 15 Jun 2009, Don Stewart wrote:

> keithshep:
>> The answer is sometimes (only if you use an optimize flag):
> You're turning on the strictness analyser. That's enabled with -O or
> -O2.
> But sum should be using a tail recursive foldl'. It's a bug in the H98
> report, IMO.

I can wrap an accumulator lazily:

data Accum a = Accum a

Then foldl' using (Accum a) instead of 'a' would be non-strict, again. 
Thus foldl' is not always strict. I think this 'seq' function is broken 
and there should have been a Seq class. Then you can choose the required 
depth of strictness.

Btw. for lazy Peano numbers, sum would be better a foldr rather than 

More information about the Haskell-Cafe mailing list