[Haskell] specification of sum

Lennart Augustsson lennart at augustsson.net
Wed Nov 2 12:58:58 EST 2005

Simon Marlow wrote:
> On 02 November 2005 00:20, Lennart Augustsson wrote:
>>Furthermore, ghc has a WRONG definition of sum.
> Surely not... sum is defined by Haskell 98 as:
>  sum = foldl (+) 0
> and this is exactly what GHC provides.  Furthermore we have specialised
> strict versions for Int and Integer.
> Also, we shouldn't be turning overloaded functions into class methods
> purely for the purposes of providing optimised versions; that's what the
> SPECIALISE pragma is for.

You are absolutly right, sum is defined with foldl.
I wonder why my hbc prelude had it defined with foldr?
(This should teach me not to look at bit rotted code.)

	-- Lennart

More information about the Haskell mailing list