Standard Either type like in Haskell


#1

Is there one? If there is, how to access and use it? If there isn’t, is there some kind of third party library containing it?


#2

Yes, the following type is now standard since 4.03.0 (released in April 2016):

type ('a, 'b) result = Ok of 'a | Error of 'b

It is not as agnostic as left/right, so it might be better to redefine your own for certain usages


#3

Base also has an Either type that is less opinionated about the
meaning of the two variants:

https://ocaml.janestreet.com/ocaml-core/latest/doc/base/Base/Either/