[Haskell] specification of sum

Scherrer, Chad Chad.Scherrer at pnl.gov
Tue Nov 1 19:39:02 EST 2005


> 
> You don't always want (+) to be strict. Consider working with 
> the ring of formal power series over, say, the integers. You 
> don't want (+) to force the evaluation of an infinite formal 
> summation which is passed to it, since that's an infinite 
> loop, so it will have to be non-strict, somewhat like zipWith 
> (+) over the lists of coefficients.
> 
>  - Cale

Hmm, this is a good point, but for most people, It seems like the most
common usage would be to add up a list of actual concrete numbers, and
the resulting memory leak in the code using sum is at least a minor
annoyance. It's hard to say how much time a given newbie will take to
catch this nuance. Since 

sum' = foldl' (+) 0

(like foldl', the ' means "strict" ) is so often preferable, I'll go so
far as to suggest it be included it in upcoming versions of Data.List.
That way it would be hard to miss, and would remove what could otherwise
be a very common stumbling block for anyone doing numerical work with
Haskell.

I haven't used product so extensively, but I suspect there may be
similar issues with it?

-Chad


More information about the Haskell mailing list