aboutsummaryrefslogtreecommitdiff
path: root/lib/option.ml
diff options
context:
space:
mode:
authoraspiwack2007-12-06 17:36:14 +0000
committeraspiwack2007-12-06 17:36:14 +0000
commita59b644de4234fb7fe3fce28284979091f257130 (patch)
treed5d8ff609aa9e4e582a06ca865a94eee1edbf182 /lib/option.ml
parent3e3fa18a066feae44c10fc6e072059f4e9914656 (diff)
Plus de combinateurs sont passés de Util à Option. Le module Options
devient Flags. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@10348 85f007b7-540e-0410-9357-904b9bb8a0f7
Diffstat (limited to 'lib/option.ml')
-rw-r--r--lib/option.ml27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/option.ml b/lib/option.ml
index 0ed36b0026..436358b555 100644
--- a/lib/option.ml
+++ b/lib/option.ml
@@ -32,6 +32,14 @@ let get = function
(** [make x] returns [Some x]. *)
let make x = Some x
+(** [init b x] returns [Some x] if [b] is [true] and [None] otherwise. *)
+let init b x =
+ if b then
+ Some x
+ else
+ None
+
+
(** [flatten x] is [Some y] if [x] is [Some (Some y)] and [None] otherwise. *)
let flatten = function
| Some (Some y) -> Some y
@@ -120,3 +128,22 @@ let lift2 f x y =
match x,y with
| Some z, Some w -> Some (f z w)
| _,_ -> None
+
+
+
+(** {6 Operations with Lists} *)
+
+module List =
+ struct
+ (** [List.cons x l] equals [y::l] if [x] is [Some y] and [l] otherwise. *)
+ let cons x l =
+ match x with
+ | Some y -> y::l
+ | _ -> l
+
+ (** [List.flatten l] is the list of all the [y]s such that [l] contains
+ [Some y] (in the same order). *)
+ let rec flatten = function
+ | x::l -> cons x (flatten l)
+ | [] -> []
+end