The way I like to reason about these things
Prelude> :t (>>=)Since the Monad m in this definition is Maybe, I'll just substitute it in like so:
(>>=) :: Monad m => m a -> (a -> m b) -> m b
Maybe a -> (a -> Maybe b) -> Maybe b
Then you notice that f is not (a -> b), it is (a -> Maybe b).On Thu, Dec 20, 2012 at 9:07 AM, Trung Quang Nguyen <trungnq97@gmail.com> wrote:
_______________________________________________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?--Trung
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners