Recommendations for Either module provider

I’m setting up CI for a new project (GitHub - joelburget/monaco-ocaml: Ocaml bindings to Microsoft's Monaco editor). I was disappointed to find that it’s [broken] on 4.08 - 4.11 because the standard library apparently didn’t include Either yet. I can think of three possible paths forward:

  1. Disable CI on the old OCaml versions (is this possible?)
  2. Define my own Either module in my package. I don’t like this very much because it’s rebuilding something that should be provided. (a) I’ll have to provide a few standard utilities that are basically just boilerplate and (b) if someone is using Either from the standard library they’ll have to convert between the two.
  3. Use Either from containers, batteries, or base. Is one of these a better choice than the others? I assume everything except Either will be linked out if it’s the only module I use, right? This also has problem 2b I believe.

Please advise which to choose.

If Either is the only module you need then you can also use the compatibility package available at opam - either

This will allow your project to use the new Either module while staying compatible with older versions of OCaml. When using compiler versions >= 4.12 the library defines an alias to the stdlib’s definition of the Either module, and in older releases it’ll provide a definition of an Either module.

1 Like

You can use the opam either compatibility package. It should be empty
on recent versions of OCaml, and redefine Either on older versions.

2 Likes

Thank you both. The either package was exactly what I needed.

Another option is to not use Either…

  1. Disable CI on the old OCaml versions (is this possible?)

ocaml-ci will test whatever versions of OCaml have a solution to your opam constraints. So if you want to restrict the versions to test, just edit your opam file to require ocaml>=4.12.

1 Like