
On Wed, 13 Sep 2006, Lennart Augustsson wrote:
The sum function really only needs the argument list to be a monoid. And the same is true for the product function, but with 1 and * as the monoid operators. Sum and product are really the same function. :)
... which got the same name, too, namely 'foldl'. 'sum' and 'product' derive the operation and the neutral element from the operand types, 'foldl' expect them explicitly.
I don't think Haskell really has the mechanisms for setting up an algebraic class hierarchy the right way. Consider some classes we might want to build: SemiGroup Monoid AbelianMonoid Group AbelianGroup SemiRing Ring ...
The problem is that going from, say, AbelianMonoid to SemiRing you want to add a new Monoid (the multiplicative) to the class. So SemiRing is a subclass of Monoid in two different way, both for + and for *. I don't know of any nice way to express this is Haskell.
Thanks for confirming what I wrote. :-)