[Haskell-cafe] A question about "monad laws"

ajb at spamcop.net ajb at spamcop.net
Wed Mar 12 20:53:52 EDT 2008


G'day all.

Quoting askyle <valgarv at gmx.net>:

> If you use this presentation you also need the following law:
> (a . b) >=> c  = (a >=> c) . b
>
> that is, compatibility with ordinary function composition. I like to call
> this "naturality", since it's instrumental in proving return and bind to be
> natural transformations.

Define:

     f >=> g = \x -> f x >>= g
     fmap f xs = xs >>= return . f

Then:

   fmap f . return
= (expand fmap)
   \x -> (return x >>= return . f)
= (defn. of >=>)
   \x -> (return >=> return . f) x
= (left identity)
   \x -> (return . f) x
=
   return . f

Therefore return is natural.

Bind (or, equivalently, join) is left as an exercise.

Cheers,
Andrew Bromage


More information about the Haskell-Cafe mailing list