diff options
Diffstat (limited to 'lib/ocaml_rts/linksem/src_lem_library/either.ml')
| -rw-r--r-- | lib/ocaml_rts/linksem/src_lem_library/either.ml | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/ocaml_rts/linksem/src_lem_library/either.ml b/lib/ocaml_rts/linksem/src_lem_library/either.ml new file mode 100644 index 00000000..ddf1b214 --- /dev/null +++ b/lib/ocaml_rts/linksem/src_lem_library/either.ml @@ -0,0 +1,24 @@ +type ('a, 'b) either = + | Left of 'a + | Right of 'b + +let either_case fa fb x = match x with + | (Left a) -> fa a + | (Right b) -> fb b + +let eitherEqualBy eql eqr (left: ('a, 'b) either) (right: ('a, 'b) either) = + match (left, right) with + | ((Left l), (Left l')) -> eql l l' + | ((Right r), (Right r')) -> eqr r r' + | _ -> false + +let rec either_partition l = ((match l with + | [] -> ([], []) + | x :: xs -> begin + let (ll, rl) = (either_partition xs) in + (match x with + | (Left l) -> ((l::ll), rl) + | (Right r) -> (ll, (r::rl)) + ) + end +)) |
