IO Monad for OCaml

Chet, don’t put words in my mouth :slight_smile: Back in 1992 I didn’t really know about monads… Today, I think monads can be extremely useful in OCaml, for things like lightweight concurrency (LWT), CPS programming, backtracking, etc.

Nonetheless, it is true that if all you want is state, exceptions,or I/O you could just as well use the built-in state, exception,or I/O mechanisms; going through a monad will not buy you much by itself.

So, to try to answer the original question: yes, you can define an I/O monad pretty much like in Haskell (e.g. as a state monad where the state is just (), the unit value), but the benefits are unclear compared to just using I/O functions without monadic encapsulation.

8 Likes