[Haskell-cafe] vector-space and standard API for vectors

wren ng thornton wren at freegeek.org
Sat Oct 23 19:52:12 EDT 2010


On 10/23/10 5:19 PM, Daniel Peebles wrote:
> Just out of curiosity, why do you (and many others I've seen with similar
> proposals) talk about additive monoids? are they somehow fundamentally
> different from multiplicative monoids? Or is it just a matter of notation?
> When I was playing with building an algebraic hierarchy, I picked a
> "neutral" operator for my monoids (I actually started at magma, but it's the
> same thing) and then introduced the addition and multiplication distinction
> at semirings, as it seemed pointless to distinguish them until you have a
> notion of a distributive law between the two.

Mathematically speaking, of course you're right about the distinction 
only mattering once you get to semirings et al. But problems arise re 
the type class system and how to use it.

For example, in many contexts we just want a monoid and we don't care 
what kind it is (e.g., fun with fingertrees). For these, it's fine to 
use a neutral monoid with newtype wrappers to capture the multiple 
monoidal structures on certain types.

But in many other contexts we want to have multiple monoids in scope at 
once (e.g., when dealing with semirings,...). For these, the newtype 
approach is a nightmare of illegibility, so we should have (at least) 
two classes ((+),0) and ((*),1).

The question then becomes: which of these is the "primary" situation? If 
neutral monoids are (as H98 and H2010 assume), then one of the two 
classes for semirings could be the same as the neutral class (as in Ed's 
monads). But then, how should we decide whether the additive or 
multiplicative structure is more "neutral"? And why should there be this 
syntactic imbalance when, mathematically, there isn't?

I'd argue that neither usage is "primary", and therefore the best 
solution is actually to have three classes (neutral, additive, and 
multiplicative) with two functors (additive->neutral, 
multiplicative->neutral) to connect them[1]. In addition to removing the 
need to argue for primacy, it also removes the need to remember which 
monoid is considered the "neutral" one, as well as removing the 
syntactic imbalance between them. Both multiplicative and additive 
monoids would be on the base type, whereas the two neutral monoids would 
be newtypes.


[1] the Exp/Log isomorphism between additive and multiplicative are not 
considered here, as there are good arguments both for using newtypes and 
for not using them.

-- 
Live well,
~wren


More information about the Haskell-Cafe mailing list