Me> class Monad m where
Me> map :: (a -> b) -> (f a -> f b) -- Functor
Me> return :: a -> m a -- Unit
Me> (>>=) :: m a -> (a -> m b) -> m b -- Kleisli multiplication
Me> or join :: m(m a) -> m a -- Monoid multiplication
Me> -- Some axioms are missing here.
Me>
Tony Davie wrote:
> I'm really worried about whether ordinary mortals (or at any rate
> programmers) will not be put off by these terms.
> It's all very well for mathematicians. Do we have to be mathematicians to
> make use of monoidal programming ideas?
Koen Claessen wrote:
>>What terms do you mean?
At 11:54 97/05/14, Tony Davie wrote:
>What I am trying to say is that it would appear that to make effective use
>of the Haskell class structure vis-a-vis monads, one needs to know about
>several category theoretical concepts in addition to monads themselves,
>Functors, Monoids and Kleisli multiplication. I personally have never heard
>of the last of these three.
I just tried to be exact, so that people knowing the theory behind it
would know what I am speaking about:
In fact, people are already implicitly using most of it, without
bothering about naming. The terminology is not very difficult:
The Haskell monad multiplication
(>>=) :: m a -> (a -> m b) -> m b
can be viewed as the function composition in the Kleisli category
construction, if one assumes that one has a category where the objects have
elements, and is doing some rewriting. So, this is what everybody uses. (A
category only has objects and arrows, called morphisms, so from that
abstract point of view, one does not know if the objects have elements,
like sets do.)
The important Haskell monad examples also have a functor
map :: (a -> b) -> (f a -> f b) -- Functor
implicitly defined. So people uses this too, implicitly, even though it is
not written down explicitly.
The map called the "join" in Haskell
join :: m(m a) -> m a -- Monoid multiplication
is in fact the original category theoretical definition of the monad
multiplication. Assuming that one has a functor and a natural
transformation unit, called in Haskell
return :: a -> m a -- Unit
then the Kleisi multiplication and the join are equivalent definitions of
the monad multiplication.
A monoid is a number system with a unit and an associative
multiplication. One can define the notion of a monoid in a category, too;
if you take a monoid in the endomorhism category End(C) of your working
category C, then this is exactly what is called a monad in the category C.
The multiplication of the monoid in End(C) is then the same as the
multiplication of the monad in C, which explains why I called it the
"monoid multiplication" version of the monad. The name "monad" is also
derived, in view of this connection, from the word "monoid" (another name
for "monad" is "triple").
Somewhat involved perhaps, but not really difficult. :-)
Hans Aberg