I just wrote a small package,
domain-shims, that provides a non-multicore implementation of the new
Domain module of the OCaml 5 standard library:
the one source file: https://gitlab.com/gasche/domain-shims/-/blob/trunk/lib/domain.ml
This is a fun hack, but it may also be useful for people who write some code using
Domain to test it under OCaml 5, but still want to be able to build and run their project using their normal OCaml 4 setup.
I haven’t put a version number and made a formal release yet.
The main limitation of the library is that it does not implement the
Effect module providing effect handlers, so it is not true that all OCaml 5 code will be compatible. I discuss this in more details in the README # no effect support, quoted below:
OCaml 5 also provides effect handlers as a new
Effectmodule of the standard library. We do not provide an implementation of
Effect, which is much harder to emulate using regular OCaml 4.
Someone could experiment with an implementation using the delimcc library for delimited control. (Please do this and report! It is probably fun.) We expect that the result would be much slower than the OCaml 5 implementation, probably by an order of magnitude. This would be okay for toy experiments. But it would not be good enough to seriously run libraries relying on effect handlers for performance-sensitive operations, such as Domainslib or Eio.
The other option would be to implement shim versions of Effect-using libraries. We are considering providing a shim for Domainslib in particular, which is very easy to do without emulating effects at all. This general approach sounds scary (no limit to the number of programs you need to provide shims for), but remember that OCaml 5 users are not supposed to use effect handlers too much yet, it was only made available for lightweight concurrent schedulers.