4 ms·
Nitpicking, but: // of type B. ">>=" instead takes in something of type M[A], // a function from (A -> B) and produces something of type // M[B]. The ty
by tomjakubowski 14y ago
Nitpicking, but:
// of type B. ">>=" instead takes in something of type M[A],
// a function from (A -> B) and produces something of type
// M[B].
The type of ">>=" is M a -> (a -> M b) -> M b, which lets you 'chain' the result of one monadic function (a -> M b) to another monadic function. So, for example:
return :: String -> IO String
putStrLn :: String -> IO ()
getLine :: IO String
return "foo" >>= putStrLn :: IO () -- prints "foo"
getLine >>= putStrLn :: IO () -- gets a line of input, then prints it
- necubi 14y agoOops, yeah, the map function above composes its argument with return, giving it the type M a -> (a -> b) -> M b, making it equivalent to the Haskell `liftm` function.