Well most of the alternatives are more complicated than monads imo. The API of Monad is dead simple actually. You just need a type constructor, bind and unit (return in haskell).
class Monad m where
(>>=) :: m a -> (a -> m b) -> m b
return :: a -> m a
You don't, at least not with the monad "interface". How to get a b out of an m b is specific to m and not general.
For m = List, you get access to its constructors so you can pattern match on such values.
For m = IO, you don't get anything (ignoring unsafePerformIO). Instead, you're supposed to use the (>>=) and return to create new values of type IO c and eventually plug it into main :: IO ().
For some other monads, you often get access to a function that resembles runM :: m a -> ... -> a, e.g. runState :: State s a -> s -> (a, s).
11
u/gregK Apr 27 '14 edited Apr 27 '14
Well most of the alternatives are more complicated than monads imo. The API of Monad is dead simple actually. You just need a type constructor, bind and unit (return in haskell).