At 13:18 97/05/16, [EMAIL PROTECTED] wrote:

>I'm the one responsible for adding the Monad laws to the Haskell
>report [library] - so perhaps I should explain why I wanted to add them.

  I had a look at these library monad laws, and, actually, it turns out
that the
        liftM :: (Monad m) => (a -> b) -> (m a -> m b)
function is the functor of the monad, called "map" in Haskell. Thus, the
monad definition should be something like
    class Functor m => Monad m  where
        (>>=)       :: m a -> (a -> m b) -> m b
        return      :: a -> m a

        (>>)        :: m a -> m b -> m b
        m >> k      =  m >>= \_ -> k

        map         :: (a -> b) -> (m a -> m b)
        map f       = \x -> (x >>= \y -> return f y)
where the "map" thus is purely defined in terms of >>=, "return", and other
Hskell primitives.

  For those interested in the mathematics behind it, the Kleisli
multiplication, which in category theory is a map
        Mor(A, M(B)) -> Mor(M(A), M(B))
where M is the monad functor, is required to be natural in its arguments.
The formula for the naturality in the contravariant argument can then be
used to define the functor values M(f), for morphisms f: A -> B.

  -- This is in fact what the formula for "liftM" says, which works,
because one implicitly assumes this naturality of the Kliesli
multiplication, then.

  Hans Aberg





Reply via email to