From 28a2641df29cd7530c3ebe329dc118ba3f444b10 Mon Sep 17 00:00:00 2001 From: Pierre-Marie Pédrot Date: Sun, 2 Mar 2014 20:40:16 +0100 Subject: Fixing generic hashes and replacing them with proper ones. --- lib/option.ml | 4 ++++ lib/option.mli | 3 +++ 2 files changed, 7 insertions(+) (limited to 'lib') 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 -- cgit v1.2.3