by grumpyprole · 3y ago · 0 comments
For a great example of this, see OCaml 5 support for effect handlers. It's basically a generalisation of exceptions, very lightweight and elegant. I can't help but think this approach would have been a much better fit for Rust than the current async effort. Monads like Async and Result are a slippery slope into the world of FP, something Rust will never excel at. Effect handlers are an alternative which arguably better align with systems programming.
A similar approach is being explored for Scala 3:
- https://dotty.epfl.ch/docs/reference/experimental/canthrow.h...
- https://infoscience.epfl.ch/record/290885
- https://github.com/lampepfl/monadic-reflection (https://youtu.be/UmO-f0qTRSU)
For example, Nim has an effect system (of sorts) and I've been curious what the leap to "generalisation of exceptions" would look like for a systems language. It does feel to me like error's and async's both should remain orthogonal to most functions but we haven't had a good theory for it. What are the missing pieces and what have the OCaml5 folks been up to?!
I encourage you to have a look at the published paper, it's an easy read and covers the motivation and examples:
https://arxiv.org/abs/2104.00250
Here's an excellent talk that walks through modifying a non-trivial code base for concurrency using effect handlers:
> It does feel to me like error's and async's both should remain orthogonal
They aren't completely orthogonal though, as both are effects. Haskell and Rust model both with Monads. OCaml 5 can model both with effect handlers. It is desirable to track the difference in types, this is something I hope the OCaml folks will add in the future.