diff options
author | Gabriel Scherer <gabriel.scherer@gmail.com> | 2019-10-20 11:00:22 +0200 |
---|---|---|
committer | Gabriel Scherer <gabriel.scherer@gmail.com> | 2020-09-02 13:59:53 +0200 |
commit | 25e59d63d8b3f86cbd3f0998650d9a580006919f (patch) | |
tree | 30618b256c4e8e49c0e7cd1148f273c35f0fe992 /stdlib/stdlib.mli | |
parent | 5cc12b8100aae9c808c66f13713f3673f7b0ed3e (diff) | |
download | ocaml-25e59d63d8b3f86cbd3f0998650d9a580006919f.tar.gz |
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.
Diffstat (limited to 'stdlib/stdlib.mli')
-rw-r--r-- | stdlib/stdlib.mli | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/stdlib/stdlib.mli b/stdlib/stdlib.mli index efd5e9a974..7d7b56f44b 100644 --- a/stdlib/stdlib.mli +++ b/stdlib/stdlib.mli @@ -1347,6 +1347,7 @@ module Callback = Callback module Char = Char module Complex = Complex module Digest = Digest +module Either = Either module Ephemeron = Ephemeron module Filename = Filename module Float = Float |