Should I link the result to the Monad?

Below is an example from the Haskell Tutorial

instance Monad Maybe where  
    return x = Just x  
    Nothing >>= f = Nothing  
    Just x >>= f  = f x  
    fail _ = Nothing  

However, the line confuses me Just x.... Should the result not be a monad? I expect the string to be

Just x >>= f = Just (f x)
+4
source share
1 answer

Yes! You are right that the result was the Monad, but keep in mind the type of operator >>=: m a -> (a -> m b) -> m b. Then we assume that it fhas a type a -> m b, so applying fto xreturns a monad as a result.

+9
source

Source: https://habr.com/ru/post/1669430/


All Articles