[Haskell-cafe] Re: Numeric type classes

David Menendez zednenem at psualum.com
Thu Sep 14 15:28:02 EDT 2006


Ross Paterson writes:

> On Thu, Sep 14, 2006 at 01:11:56AM -0400, David Menendez wrote:
> > Coincidentally, I spent some time last week thinking about a
> > replacement for the Num class. I think I managed to come up with
> > something that's more flexible than Num, but still mostly
> > comprehensible.
> 
> The fact that the first part of your structure is much the same as
> the one on the web page (which is essentially that part of the revised
> numeric prelude plus a Haskell 98-compatible veneer) is evidence that
> it's pretty clear what to do with Num and Fractional.

That being said, I don't expect anything to change.

I've looked through the revised numeric prelude, but the qualified class
names put me off. Everything shows up in Haddock as "C". Also, it
doesn't support naturals--which, admittedly, is not a big loss.

> The only point of contention is whether to factor out monoid and
> semiring classes.  Arguments against include:
> 
>  * There are lots of monoids, and (+) doesn't seem a reasonable symbol
>    for some of them.

True enough. (At least it's more general than "mappend".)

I would expect all the more specific monoid operators, like (||) and
(++), to stick around for readability when not writing
non-monoid-generic code. Not to mention that (+) and (++) associate
differently.

>  * Having (+) work on lists, tuples and all the other monoids would
>    make error messages more complicated.

It gets worse than that. Imagine trying to explain to someone why "1 +
sin" is actually "\a -> const 1 a + sin a".

On the other hand, tuples could be made an instance of Num right now.
-- 
David Menendez <zednenem at psualum.com> | "In this house, we obey the laws
<http://www.eyrie.org/~zednenem>      |        of thermodynamics!"


More information about the Haskell-Cafe mailing list