On 20 Dec 2012, at 14:07, Trung Quang Nguyen <trungnq97@gmail.com> wrote:

Hi all,

I saw this

  1. instance Monad Maybe where  
  2.     return x = Just x  
  3.     Nothing >>= f = Nothing  
  4.     Just x >>=  = f x  
  5.     fail _ = Nothing  

I am wondering about the implementation of function (>>=). Why don't it be Just x >>= f = Just (f x)?

Any body knows about this?

The reason is in the type of bind:

(>>=) :: Monad m => m a -> (a -> m b) -> m b

The function f takes a non-in-a-monad value, and gives you an in-a-monad value.

Bob