From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA05748 for caml-redist; Fri, 28 Apr 2000 12:17:34 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA10033 for ; Fri, 28 Apr 2000 10:09:56 +0200 (MET DST) Received: from esrelay002.caissedesdepots.fr (esrelay002.caissedesdepots.fr [158.156.156.29]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id KAA01346 for ; Fri, 28 Apr 2000 10:09:55 +0200 (MET DST) Received: from esmailfed2.serv.cdc.fr (esmailfed2 [158.156.1.207]) by esrelay002.caissedesdepots.fr (8.8.8+Sun/8.8.8) with ESMTP id KAA21550 for ; Fri, 28 Apr 2000 10:11:08 +0200 (MET DST) Received: from tsexchange.idt.cdc.fr (localhost [127.0.0.1]) by esmailfed2.serv.cdc.fr (8.8.8/8.8.8) with ESMTP id KAA23908 for ; Fri, 28 Apr 2000 10:11:34 +0200 (MET DST) Received: by tsexchange.idt.cdc.fr with Internet Mail Service (5.5.2448.0) id ; Fri, 28 Apr 2000 10:14:49 +0200 Message-ID: <40C4228EC468D211B04800A0C9DF1D6636DE0E@tsexchange.idt.cdc.fr> From: "Coscoy, Yann" To: caml-list@inria.fr Subject: RE: hashtables for mutable records Date: Fri, 28 Apr 2000 10:14:48 +0200 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2448.0) Content-Type: text/plain; charset="iso-8859-1" Sender: weis Hello, Pierre Weis wrote : > You can use a unique integer field into your records It is the solution I use. But, I dislike it because it makes necessary to embed the record in some abstract type. (You must hide the constructor of the recors to guaranty the uniqueness of the integer.) > Of course you must use your own hashing function that just reads this fixed integer field. I can do that, but it make impossible to use Hashtbl.Make because of the poymorphism of the record. > As of polymorphism, if your problem is just to have keys or values > belonging to a parameterized data type, you can directly use the > creation and manipulation functions from the Hashtbl module > (Hashtbl.create, Hashtbl.add, etc): they accept to manipulate > polymorphic tables. Since usage of these functions with a user defined > hash function is not available from the Hashtbl module, you should > rewrite some parts of its code into your own hash table module. I know I can solve my problem in this way. But I don't think that "cut, paste, and patch the stdlib" is a good practice. So, I prefer to use the integer itself as the key of hashtable and use the standard Hash module. I partial solution would be to have another functor Make1 in module Hashtbl with type 'a key. (It is just a partial solution, because it doesn't solve the problem for type ('a, 'b) key and type ('a, 'b, 'c) key.) Yann coscoy PS: the signature of this Make1 functor: module type HashedType1 = sig type 'a t val equal: 'a t -> 'a t -> bool val hash: 'a t -> int end module type S1 = sig type 'a key type ('a, 'b) t val create: int -> ('a, 'b) t val clear: ('a, 'b) t -> unit val add: ('a, 'b) t -> 'a key -> 'b -> unit val remove: ('a, 'b) t -> 'a key -> unit .....