Here is another monad definition improving aspect you may think of:
If one defines a monad as
class Monad m where
map :: (a -> b) -> (m a -> m b) -- Functor
return :: a -> m a -- Unit
(>>=) :: m a -> (a -> m b) -> m b -- Kleisli multiplication
or join :: m(m a) -> m a -- Monoid multiplication
-- Some axioms are missing here.
then one missing axiom, that the unit "return" should be a natural
transformation, translates into that the following diagram is commutative:
return: a -> m a
f | # | map(f)
v v
return: b -> m b
for any function f. (In category theory, the hash "#" means that the
diagram is commutative, that is, going the different ways, yields the same
result.)
Is there any way to express this requirement in Haskell?
-- The theoretical problem is that if you is not have this natural
transformation property of the unit "return", and also of the join and the
(>>=), then the join and (>>=) are not equivalent (and you do not get the
other nice theoretical properties of a monad).
Hans Aberg