Why do we even need monads?
- Monads encapsulate impure side effects and other effects, making them pure.
- Monads allow sequencing of operations without resorting to statements.
- Monads (with LINQ) allow us to write pure code that looks a lot like statements in imperative code.
- Monads de-clutter your code making it more declarative.
Quite simply: Monads are the 'statements' of pure functional programming and they encapsulate messy boilerplate and side-effects.
For a deeper dive into the 'why?' of monads, then check out Paul Louth's Higher-Kinds series.
- Monad is the home of the main
Monad<M>
trait as well as its extension methods andMonad
module type. - MonadIO has the IO variant of the monad that allows lifting of the
IO<A>
monad into a monad-transformer stack. - MonadT has the
MonadT<T, M>
monad-transformer trait, it allows the lifting of a monadM
into a monad-transformerT
.