4 ms·
OCaml is currently going through something similar, with some solutions in sight. The "motivation" part of the eio (https://github.com/ocaml-multicore/eio https
by Zababa 5y ago
OCaml is currently going through something similar, with some solutions in sight. The "motivation" part of the eio (https://github.com/ocaml-multicore/eio https://github.com/ocaml-multicore/eio) documentation is a great introduction:
"The Unix library provided with OCaml uses blocking IO operations, and is not well suited to concurrent programs such as network services or interactive applications. For many years, the solution to this has been libraries such as Lwt and Async, which provide a monadic interface. These libraries allow writing code as if there were multiple threads of execution, each with their own stack, but the stacks are simulated using the heap.
The multicore version of OCaml adds support for "effects", removing the need for monadic code here. Using effects brings several advantages:
1. It's faster, because no heap allocations are needed to simulate a stack.
2. Concurrent code can be written in the same style as plain non-concurrent code.
3. Because a real stack is used, backtraces from exceptions work as expected.
4. Other features of the language (such as try ... with ...) can be used in concurrent code.
Additionally, modern operating systems provide high-performance alternatives to the old Unix select call. For example, Linux's io-uring system has applications write the operations they want to perform to a ring buffer, which Linux handles asynchronously."
- skohan 5y agoHow does programming with "effects" actually work? I've read the linked page, and I understand the advantages they're claiming, but I don't see any explanation of what effects actually are.
- Zababa 5y agoThere are lots of informations in "Concurrent Programming with Effect Handlers" (https://github.com/ocamllabs/ocaml-effects-tutorial https://github.com/ocamllabs/ocaml-effects-tutorial) on what it looks like and how it's implemented. There are also more recent informations on the September 2021 edition of the Multicore OCaml newsletter: https://discuss.ocaml.org/t/multicore-ocaml-september-2021-effect-handlers-will-be-in-ocaml-5-0/8554 https://discuss.ocaml.org/t/multicore-ocaml-september-2021-e..., with a link to a paper about effects in OCaml.
- scns 5y agoThe last time [0] Effects were discussed, these recommendations were made [1],[2]. [0] https://news.ycombinator.com/item?id=28838099 https://news.ycombinator.com/item?id=28838099 [1] https://www.youtube.com/watch?v=hrBq8R_kxI0 https://www.youtube.com/watch?v=hrBq8R_kxI0 [2] https://overreacted.io/algebraic-effects-for-the-rest-of-us/ https://overreacted.io/algebraic-effects-for-the-rest-of-us/