[Haskell-beginners] About monad

Miguel Negrao miguel.negrao-lists at friendlyvirus.org
Thu Dec 20 16:25:10 CET 2012


A 20/12/2012, às 14:07, Trung Quang Nguyen escreveu:

> Hi all,
> 
> I saw this
> 
> 	• instance Monad Maybe where  
> 	•     return x = Just x  
> 	•     Nothing >>= f = Nothing  
> 	•     Just x >>= f  = f x  
> 	•     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?

That would be the implementation of fmap for Maybe:

instance  Functor Maybe  where
    fmap _ Nothing       = Nothing
    fmap f (Just a)      = Just (f a)

so, different behavior.

best,
Miguel


More information about the Beginners mailing list