Hello,


On 14 May 2008, at 02:06, Ronald Guida wrote:

I have a few questions about commutative monads and applicative functors.

From what I have read about applicative functors, they are weaker than
monads because with a monad, I can use the results of a computation to
select between alternative future computations and their side effects,
whereas with an applicative functor, I can only select between the
results of computations, while the structure of those computations and
their side effects are fixed in advance.

But then there are commutative monads.  I'm not exactly sure what a
commutative monad is, but my understanding is that in a commutative
monad the order of side effects does not matter.

This leads me to wonder, are commutative monads still stronger than
applicative functors, or are they equivalent?


I would say that they are stronger because they still support:

concat :: Monad m => m (m a) -> m a

or

(>>=) :: Monad m => m a -> (a -> m b) -> m b

which are not supported, in general, by applicative functors.

In fact, I would probably risk to say that they are even stronger than monads
(as there are less commutative monads than regular monads).

And by the way, what exactly is a commutative monad?


Here is a possible characterization:

The monad m is commutative if, for all mx and my:

do {x <- mx; y <- my; return (x,y)} = do {y <- my; x <- mx; return (x,y)}

As you mentioned above, the basic idea is that the order of the side effects 
does not matter. This law is not true in general for monads.

I am not sure if you know about the paper entitled "The essence of the 
Iterator Pattern" (by Jeremy Gibbons and myself):

http://www.comlab.ox.ac.uk/people/Bruno.Oliveira/iterator-jfp.pdf

But, you may be interested to read it as it discusses related ideas. In 
particular you may want to take a look at Section 5.4. 

Cheers,

Bruno