Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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 (http://www.lri.fr/~filliatr)

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr