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

askyle valgarv at gmx.net
Sat Mar 15 05:17:06 EDT 2008



ajb-2 wrote:
> 
> If you wanted to prove that bind is natural, you would need to define
> bind, no?
> 

Yup: bind f = f <=< id         -- whence you can say (>>=) = flip bind
My point is that (as far as I can see) you cannot prove the properties of
bind
by only assuming identity and associativity for (<=<). You need some way to
relate (<=<) to normal composition.

To be more explicit:

Given:
1. m :: * -> *
2. return :: a -> m a
3. (<=<) :: (b -> m c) -> (a -> m b) -> (a -> m c)
such that:
1. return <=< f === f <=< return === f
2. (f <=< g) <=< h === f <=< (g <=< h)

Define:
bind f = f <=< id
(>>=) = flip bind
fmap f = bind (return . f)
join = bind id

Show the monad laws hold, either for (return,bind), (return,(>>=)) or
(fmap,return,join) (in the latter case, there's also showing that fmap is
a functor and return and join are natural transformations).

If someone can show it can be done without also assuming:
3. (f <=< g) . h === f <=< (g . h)
I'll stand corrected.

-----
Ariel J. Birnbaum
-- 
View this message in context: http://www.nabble.com/A-question-about-%22monad-laws%22-tp15411587p16065960.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list