[Haskell-cafe] Thoughts about redesigning "Num" type class
allbery.b at gmail.com
Mon Sep 7 14:47:46 UTC 2015
On Mon, Sep 7, 2015 at 10:08 AM, DreamApart AtHaskells <rnmss.hs at gmail.com>
> 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
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
brandon s allbery kf8nh sine nomine associates
allbery.b at gmail.com ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe