diff --git a/infer/src/istd/IOption.ml b/infer/src/istd/IOption.ml index 478d01a86..8c6981f38 100644 --- a/infer/src/istd/IOption.ml +++ b/infer/src/istd/IOption.ml @@ -14,3 +14,15 @@ let value_default_f ~f = function None -> f () | Some v -> v let if_none_evalopt ~f x = match x with None -> f () | Some _ -> x let if_none_eval = value_default_f + +module Let_syntax = struct + include Option.Let_syntax + + let ( let+ ) x f = Option.map ~f x + + let ( and+ ) x y = Option.both x y + + let ( let* ) x f = Option.bind ~f x + + let ( and* ) x y = Option.both x y +end diff --git a/infer/src/istd/IOption.mli b/infer/src/istd/IOption.mli index 7bf2c317f..c5eccf325 100644 --- a/infer/src/istd/IOption.mli +++ b/infer/src/istd/IOption.mli @@ -21,3 +21,20 @@ val if_none_eval : f:(unit -> 'a) -> 'a option -> 'a (** [if_none_eval ~f x] evaluates to [y] if [x=Some y] else to [f ()]. Useful for terminating chains built with [if_none_evalopt]. This is exactly the same as [value_default_f] but with a better name. *) + +include sig + [@@@warning "-32-60"] + + (** Provides signatures for OCaml 4.08 binding operators *) + module Let_syntax : sig + include module type of Option.Let_syntax + + val ( let+ ) : 'a option -> ('a -> 'b) -> 'b option + + val ( and+ ) : 'a option -> 'b option -> ('a * 'b) option + + val ( let* ) : 'a option -> ('a -> 'b option) -> 'b option + + val ( and* ) : 'a option -> 'b option -> ('a * 'b) option + end +end