[Haskell-cafe] Thoughts about redesigning "Num" type class

Silvio Frischknecht silvio.frischi at gmail.com
Mon Sep 7 19:49:01 UTC 2015

> (+) is assuredly a monoid.
> But so is (*)! (Try looking at it through logarithms.)
> Unfortunately, a given type can have only a single instance of a given
> typeclass.
> There is in fact a way to design Num "rationally", via number theory; I
> suggest you at least familiarize yourself with that. (This will bring
> you face to face with the above issue, as it turns out that Num requires
> two monoids.) It turns out that this is not necessarily a good idea. But
> see http://hackage.haskell.org/package/numeric-prelude for an
> implementation of it.

Well, at some point you will have to make concessions. I for one, would
love to use (+) without Num or going through an entire semester of
Algebra. And DreamApart's proposal seams a reasonable compromise. I
don't see it being included into base any time soon however, as it would
break an enormous amount of code.

As for the Maybe instances. From afar, if you think of Nothing as 0 and
Just x as (not 0), the Monoid instance looks like (*) and the MonadPlus
instance looks like (+).

Also, I would prefer.

class (Monoid m) => Ring m where

class (Group a, Ring a) => Num a where



More information about the Haskell-Cafe mailing list