ocaml/testsuite/tests/lib-either
Gabriel Scherer 25e59d63d8 Add `'a Either.t = Left of 'a | Right of 'b`
```ocaml
val left : 'a -> ('a, 'b) t
val right : 'b -> ('a, 'b) t
val is_left : ('a, 'b) t -> bool
val is_right : ('a, 'b) t -> bool
val find_left : ('a, 'b) t -> 'a option
val find_right : ('a, 'b) t -> 'b option
val map_left : ('a1 -> 'a2) -> ('a1, 'b) t -> ('a2, 'b) t
val map_right : ('b1 -> 'b2) -> ('a, 'b1) t -> ('a, 'b2) t
val map : left:('a1 -> 'a2) -> right:('b1 -> 'b2) -> ('a1, 'b1) t -> ('a2, 'b2) t
val fold : left:('a -> 'c) -> right:('b -> 'c) -> ('a, 'b) t -> 'c
val equal :
  left:('a -> 'a -> bool) -> right:('b -> 'b -> bool) ->
  ('a, 'b) t -> ('a, 'b) t -> bool
val compare :
  left:('a -> 'a -> int) -> right:('b -> 'b -> int) ->
  ('a, 'b) t -> ('a, 'b) t -> int
```

Unlike [result], no [either] type is made available in Stdlib,
one needs to access [Either.t] explicitly:

- This type is less common in typical OCaml codebases,
  which prefer domain-specific variant types whose constructors
  carry more meaning.
- Adding this to Stdlib would raise warnings in existing codebases
  that already use a constructor named Left or Right:
  + when opening a module that exports such a name,
    warning 45 is raised
  + adding a second constructor of the same name in scope kicks
    in the disambiguation mechanisms, and warning 41 may now
    be raised by existing code.

If the use becomes more common in the future we can always
revisit this choice.
2020-09-02 13:59:53 +02:00
..
test.ml Add `'a Either.t = Left of 'a | Right of 'b` 2020-09-02 13:59:53 +02:00