Hans Aberg wrote:
>
> >** Postfix `M' always stands for a function in the Kleisli category:
> > m is added to function results (modulo currying) and nowhere else.
>
> I am not sure what you use this for: Given a monad M, the Kleisli
> category is equivalent to the full free monad algebra of the original
> category, that is all objects of the form M(a), and monad algebra
> homomorphisms M(a) -> M(b), so one can use this category instead.
In haskell, you only get one category anyway ;-) The functions in question
*are* the underlying functions in the original category, and are useful when
you want to pretend you're programming in the Kleisli category. It's a
matter of convenience, not existence.
So how might you use them? Say you've got some code that wasn't originally
monadic, and you now need to re-express your code in monadic form. You
apply the monad translation. Using the `kleisli' functions makes this
process simpler. Consider:
map f (... xs ...)
If we do the monad translation on the argument of `map f', we'll get (...
return xs ...). The monad translation on `f' is `return . f'. Now we need
the monad translation on `map'. Oh hey - someone's already done it for us -
it's called mapM. So now our original term with the monad translation
applied to it is:
mapM (return . f) (... return xs ...)
--Jeff