Taking OCaml and Eio for a Spin
3 days ago
- The author chose to learn OCaml due to its recent renaissance with multicore support, effects, and the OxCaml spin from Jane Street, focusing on the Eio concurrency framework.
- They started with Real World OCaml (RWO) but found it lacked exercises, so switched to CS3110 which provided better practice and then returned to RWO for advanced topics.
- OCaml offers a mix of functional and imperative programming, with named arguments, but the syntax can be wordy (e.g., let..in, match..with) and the compiler stops at the first error, slowing iteration.
- Eio is an effects-based I/O library with features like io_uring and deterministic concurrency, suitable for building a Raft consensus algorithm.
- The author implemented a simple RPC protocol using Eio flows, buffered readers/writers, streams, promises, and fibers to handle concurrent requests safely.
- The client uses a write queue and promises to manage concurrent invocations, and the server handles connections with a loop that reads and responds to procedure calls.
- Overall, OCaml is fun and easy to use, but has a small userbase, making it harder to find code examples and best practices.