For several years, OCaml 5 has been introducing shared memory parallelism support with shared memory and effect handlers that are the basis of exception handling, parallelism, asynchronous I/O, and more.
Algebraic effect handlers are a first-class abstraction designed to represent and manipulate control flow in a program. In their most immediate form, effect handlers provide an exception restart mechanism that can be used for error recovery. Due to their flexibility, they are also the basis for other abstractions, such as generators, asynchronous input/output, concurrency, etc.
Effects are associated with effect handlers, which are written with three fields: a retc function that accepts the result of a completed computation; an exnc function that is called when an exception is thrown; and a generic effc function that handles the effect.
Channels, on the other hand, are a mechanism that allows domains to communicate with each other as their name implies. Channels are blocking, meaning that if a domain tries to receive a message from a channel but the message is not ready, the domain can block. Similarly, a send operation may cause a domain to block until another domain receives that message if the channel has reached the maximum number of messages it can hold.
Currently, one of the limitations of the OCaml 5 compiler is that it only supports x86-64 and arm64 architectures on Linux, BSD, macOS, and Windows/migw64. The OCaml team is working to restore support for the other traditionally supported architectures in 2023.
Concurrency and parallelism support are not the only new features in OCaml 5, which also includes improvements to the runtime system, standard library, and several optimizations. Don’t miss the official release notes to get all the details.