class Monad m where return :: a -> m a (>>=) :: m a -> (a -> m b) -> m b
The most important function for dealing with monads is the bind operator
(>>=) :: m a -> (a -> m b) -> m b
m aas "an action with an
a -> m bas “an action (depending on an
aparameter) with a
>>= sequences two actions together by piping the result from the first action to the second.
The other function defined by
return :: a -> m a
Its name is unfortunate: this
return has nothing to do with the
return keyword found in imperative programming languages.
return x is the trivial action yielding
x as its result. (It is trivial in the following sense:)
return x >>= f ≡ f x -- “left identity” monad law x >>= return ≡ x -- “right identity” monad law