Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] some Hashtbl observations
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-02-04 (08:52)
From: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@l...>
Subject: Re: [Caml-list] some Hashtbl observations

 > D'oh!  So I guess I shouldn't use an <abstr> type as a hash key in the
 > generic Hashtbl interface.  That makes sense in hindsight.

There is  actually another issue  related to ocaml bignums  related to
generic hash and equalit functions: the lack of unique representation.
Indeed, type "num" is defined as

    type num =
        Int of int
      | Big_int of Big_int.big_int
      | Ratio of Ratio.ratio

(to improve computations over small integers or big integers not being
rationals) but a given rational may have several representations (e.g.
1 may be (Int 1) sometimes and some ratio (Ratio ...) later).

Thus, even  if hash and equality  would not fail on  the abstract type
ratio,  they would  fail to  hash  or compare  properly two  different
representations  of  the  same   number  (generic  hash  and  equality
functions are---among other things---based on constructors tags).

Hope this helps,
Jean-Christophe Filliatre (

Bug reports:  FAQ:
To unsubscribe, mail  Archives: