[Main website]


OCaml started supporting them for multithreading, advanced exception handling, async/await, async IO, probabilistic programming, and so on.

Special operations like writing to IO, or STM can be specified in a library. The handler intercept the special action and it can decide what to do, and it send an optional result and a continuation that specifies where to continue the execution. It is a sort of delimited call continuation, but with a better API. In case of OCaml, it is efficienct, because the continuation is usually a fast unwind of the stack.

Effects can pass continuation as first class value: it is equivalent to delimited continuation, with an handler. But they are more composable.

Effects support static typing. They can replace the Monad and CT approach.

[1] M. Pretnar, “An Introduction to Algebraic Effects and Handlers. Invited tutorial paper,” Electronic Notes in Theoretical Computer Science, vol. 319, pp. 19–35, Dec. 2015, doi: 10.1016/j.entcs.2015.12.003.