add Hash.const0 for trivial hash function that ignores its input

This commit is contained in:
Simon Cruanes 2017-12-15 13:49:34 +01:00
parent 632526e407
commit 9ac7984f74
2 changed files with 7 additions and 0 deletions

View file

@ -24,6 +24,7 @@ let combine4 a b c d =
(** {2 Combinators} *) (** {2 Combinators} *)
let const h _ = h let const h _ = h
let const0 _ = 0
let int i = i land max_int let int i = i land max_int
let bool b = if b then 1 else 2 let bool b = if b then 1 else 2

View file

@ -14,6 +14,12 @@ type 'a t = 'a -> hash
val const : hash -> _ t val const : hash -> _ t
(** [return h] hashes any value into [h]. Use with caution!. *) (** [return h] hashes any value into [h]. Use with caution!. *)
val const0 : _ t
(** Always return 0. Useful for ignoring elements.
Example: [Hash.(pair string const0)] will map pairs [("a", 1)]
and [("a", 2)] to the same hash, but not the same as [("b", 1)]
@since NEXT_RELEASE *)
val int : int t val int : int t
val bool : bool t val bool : bool t
val char : char t val char : char t