3 ms·
I think one thing one should ask is: If monads are the solution to X, and we add a different solution to X to the language, then what are monads for? Let’s sa
by dan-robertson 8y ago
I think one thing one should ask is:
If monads are the solution to X, and we add a different solution to X to the language, then what are monads for?
Let’s say you have imperative IO. Then promises are a Monad but then you could just add language support for async and promises are not really needed as a Monad anymore.
A more functional replacement for monads could be something like algebraic effects. These could replace monads completely or they could be like multi core ocaml and only give you one shot continuations (so not allowing for list or other multi-shot monads).
In this context I like to think about the continuation Monad. In Haskell:
newtype Cont r a = Cont { runCont :: (a -> r) -> r }
This means “some computation yielding a r which got paused part-done having just yielded an a. In some sense all monads are expressible in terms of Cont. I feel like this is largely the essence of why it is useful to have monads: they express computations which happen with some context, able to switch back and forth between things in the context and things in the normal computation. I don’t think sequencing evaluation is so important to the definition.