oleg | 23 Oct 10:28 2012

Why Kleisli composition is not in the Monad signature?

Andreas Abel wrote:
> I tell them that monads are for sequencing effects; and the
> sequencing is visible clearly in
>    (>>)  :: IO a -> IO b -> IO b
>    (>>=) :: IO a -> (a -> IO b) -> IO b
> but not in
>    fmap :: (a -> b) -> IO a -> IO b
>    join :: IO (IO a) -> IO a

Indeed! I'd like to point out an old academic paper that was written
exactly on the subject at hand: how Category Theory monads relate to
monads in Haskell. Here is the relevant quotation:

    Monads are typically equated with single-threadedness, and are
    therefore used as a technique for incorporating imperative features
    into a purely functional language. Category theory monads have little
    to do with single-threadedness; it is the sequencing imposed by
    composition that ensures single-threadedness. In a Wadler-ised monad
    this is a consequence of bundling the Kleisli star and flipped compose
    into the bind operator. There is nothing new in this connection. Peter
    Landin in his Algol 60 used functional composition to model
    semi-colon. Semi-colon can be thought of as a state transforming
    operator that threads the state of the machine throughout a program.
    The work of Peyton-Jones and Wadler has turned full circle back to
    Landin's earlier work as their use of Moggi's sequencing monad enables
    real side-effects to be incorporated into monad operations such as
(Continue reading)