Re:From Monads to Machine Code
by lacampbell on Monday April 24, 2017 @02:38AM
(#14182345)
Those two operations make sense to me. Type signatures and all.
Is that all that is needed for something to be a monad?
The operations also need to obey the "Monad Laws" https://wiki.haskell.org/Monad_laws.
But the intuitive version is that anything with those two operations that doesn't smell funny is a Monad.
(Think of it like implementing an interface: anything that matches the type signature will work, but if you write something silly, it won't work right)
The Maybe monad stops when it encounters a Nothing result, and continues when it encounters a Just. So:
will return Nothing, whereas will return Just 5.>>= is used to take the value inside the monad (Just) for the left-hand argument, and stuff it into the right-hand argument, like so:
returns Just "hello world".