aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPierre-Marie Pédrot2014-03-02 20:40:16 +0100
committerPierre-Marie Pédrot2014-03-03 01:35:09 +0100
commit28a2641df29cd7530c3ebe329dc118ba3f444b10 (patch)
tree96e334e8aa6b9227892818a707d7ac09fc99630d /lib
parent0d8a11017e45ff9b0b18af1d6cd69c66184b55ae (diff)
Fixing generic hashes and replacing them with proper ones.
Diffstat (limited to 'lib')
-rw-r--r--lib/option.ml4
-rw-r--r--lib/option.mli3
2 files changed, 7 insertions, 0 deletions
diff --git a/lib/option.ml b/lib/option.ml
index 1ef45d232e..abdae892f2 100644
--- a/lib/option.ml
+++ b/lib/option.ml
@@ -35,6 +35,10 @@ let compare f x y = match x, y with
| None, Some _ -> -1
| Some _, None -> 1
+let hash f = function
+| None -> 0
+| Some x -> f x
+
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 d390edb63a..af8696a5e4 100644
--- a/lib/option.mli
+++ b/lib/option.mli
@@ -31,6 +31,9 @@ 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
+(** Lift a hash to option types. *)
+val hash : ('a -> int) -> 'a option -> int
+
(** [get x] returns [y] where [x] is [Some y]. It raises IsNone
if [x] equals [None]. *)
val get : 'a option -> 'a