diff --git a/src/libraries/utils/option.ml b/src/libraries/utils/option.ml new file mode 100644 index 0000000000000000000000000000000000000000..fa7cea3f18a311c426a4cb23062a38d5c7648f00 --- /dev/null +++ b/src/libraries/utils/option.ml @@ -0,0 +1,32 @@ +(**************************************************************************) +(* *) +(* This file is part of Frama-C. *) +(* *) +(* Copyright (C) 2007-2023 *) +(* CEA (Commissariat à l'énergie atomique et aux énergies *) +(* alternatives) *) +(* *) +(* you can redistribute it and/or modify it under the terms of the GNU *) +(* Lesser General Public License as published by the Free Software *) +(* Foundation, version 2.1. *) +(* *) +(* It is distributed in the hope that it will be useful, *) +(* but WITHOUT ANY WARRANTY; without even the implied warranty of *) +(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *) +(* GNU Lesser General Public License for more details. *) +(* *) +(* See the GNU Lesser General Public License version 2.1 *) +(* for more details (enclosed in the file licenses/LGPLv2.1). *) +(* *) +(**************************************************************************) + +include Stdlib.Option + +let zip l r = match l, r with Some l, Some r -> Some (l, r) | _ -> None + +module Operators = struct + let ( let* ) m f = bind m f + let ( let+ ) m f = map f m + let ( and* ) l r = zip l r + let ( and+ ) l r = zip l r +end diff --git a/src/libraries/utils/option.mli b/src/libraries/utils/option.mli new file mode 100644 index 0000000000000000000000000000000000000000..d489d49c632c3b788b8a70536e156981fcfbc5e2 --- /dev/null +++ b/src/libraries/utils/option.mli @@ -0,0 +1,32 @@ +(**************************************************************************) +(* *) +(* This file is part of Frama-C. *) +(* *) +(* Copyright (C) 2007-2023 *) +(* CEA (Commissariat à l'énergie atomique et aux énergies *) +(* alternatives) *) +(* *) +(* you can redistribute it and/or modify it under the terms of the GNU *) +(* Lesser General Public License as published by the Free Software *) +(* Foundation, version 2.1. *) +(* *) +(* It is distributed in the hope that it will be useful, *) +(* but WITHOUT ANY WARRANTY; without even the implied warranty of *) +(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *) +(* GNU Lesser General Public License for more details. *) +(* *) +(* See the GNU Lesser General Public License version 2.1 *) +(* for more details (enclosed in the file licenses/LGPLv2.1). *) +(* *) +(**************************************************************************) + +include module type of Stdlib.Option + +val zip : 'a option -> 'b option -> ('a * 'b) option + +module Operators : sig + val ( let* ) : 'a option -> ('a -> 'b option) -> 'b option + val ( let+ ) : 'a option -> ('a -> 'b) -> 'b option + val ( and* ) : 'a option -> 'b option -> ('a * 'b) option + val ( and+ ) : 'a option -> 'b option -> ('a * 'b) option +end