How was "val hash:" a & # 8594; int` in OCaml?

In OCaml Hashtblcan hashadd any thing to int

Hashtbl.hash x associates a non-negative integer with any value of any type. It is guaranteed that if x = y or Pervasives.compare xy = 0, then hash x = hash y. Moreover, the hash always ends even on cyclic structures.

I mean, in Javawe have hashCode()for every object that returns an integer, and Java Hashtable can hash this integer.

But how did OCaml achieve this to hash something?

+5
source share
1 answer

. Hashtbl.hash , , . , , . , , , .

byterun/hash.c OCaml.

, , Hashtbl.hash OCaml. , OCaml ( ), . 'a -> int , . , - , .

Hashtbl.hash OCaml, . OCaml, . compare ( =).

+6

All Articles