[Haskell-cafe] Why Kleisli composition is not in the Monad signature?

oleg at okmij.org oleg at okmij.org
Tue Oct 23 10:28:37 CEST 2012

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

Quoted from: Sec 3: An historical aside
Jonathan M. D. Hill and Keith Clarke:
An Introduction to Category Theory, Category Theory Monads,
and Their Relationship to Functional Programming. 1994.

I'd like to stress: the single-threadedness, the trick that lets us
embed imperative language into a pure one, has *little to do* with
category-theoretic monads with their Klesli star. 

The web page
describes the work of Landin in detail, contrasting Landin's and
Peyton-Jones' papers.

More information about the Haskell-Cafe mailing list