[Haskell-beginners] About monad

Edward Z. Yang ezyang at MIT.EDU
Thu Dec 20 15:12:02 CET 2012


Excerpts from Trung Quang Nguyen's message of Thu Dec 20 22:07:02 +0800 2012:
> Hi all,
> 
> I saw this
> 
> 
>    1. instance Monad Maybe where
>    2.     return x = Just x
>    3.     Nothing >>= f = Nothing
>    4.     Just x >>= f  = f x
>    5.     fail _ = Nothing
> 
> 
> I am wondering about the implementation of function (>>=). Why don't
> it be *Just
> x >>= f = Just (f x)*?

Try it; it won't typecheck.

Cheers,
Edward



More information about the Beginners mailing list