On Mon, Sep 7, 2015 at 10:08 AM, DreamApart AtHaskells <rnmss.hs@gmail.com> wrote:
The class Num defines the method functions like (+), (-), (*), negate, ...
But they are actually different concepts.
We often meet situations that we want an addition for some type, but
not a multiplication. For example:
I think the concept you're reaching for here is Monoid. However, there is a(t least one) complication you did not consider:
(+) 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.