diff options
| author | Pierre-Marie Pédrot | 2014-03-01 18:26:26 +0100 |
|---|---|---|
| committer | Pierre-Marie Pédrot | 2014-03-01 22:45:39 +0100 |
| commit | 87b510e5b0f363724eae5db9f177f167a3586015 (patch) | |
| tree | 204c7ad1e1ba38945ab58d74e28d8cf67201fe71 /lib | |
| parent | bca756eaebf16b6145c65b53629219d2a0a8b1ba (diff) | |
Fixing pervasive comparisons
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/option.ml | 6 | ||||
| -rw-r--r-- | lib/option.mli | 3 |
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/option.ml b/lib/option.ml index 02adc69478..1ef45d232e 100644 --- a/lib/option.ml +++ b/lib/option.ml @@ -29,6 +29,12 @@ let equal f x y = match x, y with | Some x, Some y -> f x y | _, _ -> false +let compare f x y = match x, y with +| None, None -> 0 +| Some x, Some y -> f x y +| None, Some _ -> -1 +| Some _, None -> 1 + exception IsNone (** [get x] returns [y] where [x] is [Some y]. It raises IsNone diff --git a/lib/option.mli b/lib/option.mli index 0b50c588b1..d390edb63a 100644 --- a/lib/option.mli +++ b/lib/option.mli @@ -28,6 +28,9 @@ val is_empty : 'a option -> bool [f] is called. Otherwise it returns [false]. *) val equal : ('a -> 'a -> bool) -> 'a option -> 'a option -> bool +(** Same as [equal], but with comparison. *) +val compare : ('a -> 'a -> int) -> 'a option -> 'a option -> int + (** [get x] returns [y] where [x] is [Some y]. It raises IsNone if [x] equals [None]. *) val get : 'a option -> 'a |
