From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA03123 for caml-redist; Fri, 28 Apr 2000 12:07:49 +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 DAA20705 for ; Fri, 28 Apr 2000 03:12:36 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id DAA19269 for ; Fri, 28 Apr 2000 03:12:34 +0200 (MET DST) Received: from localhost (sansho.kurims.kyoto-u.ac.jp [130.54.16.90]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id KAA16242; Fri, 28 Apr 2000 10:12:28 +0900 (JST) To: yann.coscoy@icdc.caissedesdepots.fr Cc: caml-list@inria.fr Subject: Re: hashtables for mutable records In-Reply-To: Your message of "Thu, 27 Apr 2000 15:28:41 +0200" <40C4228EC468D211B04800A0C9DF1D6636DE0C@tsexchange.idt.cdc.fr> References: <40C4228EC468D211B04800A0C9DF1D6636DE0C@tsexchange.idt.cdc.fr> Mime-Version: 1.0 X-Mailer: Mew version 1.93 on Emacs 20.5 / Mule 4.0 (HANANOEN) Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20000428101227D.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 28 Apr 2000 10:12:27 +0900 From: Jacques Garrigue X-Dispatcher: imput version 980905(IM100) Sender: weis From: "Coscoy, Yann" > I want to do an hashtable on mutable and polymorphic records. Standard > module Hashtbl is not suitable because: > - Hashtbl.HashType doesn't accept polymorphic types. > - Hashtbl.hash is susceptible to setups of a mutable fields. The standard functorial solution would be to define a new functor: type 'a polyref = {mutable data: 'a; id: int} module PolyHash(T : sig type t end) = Hashtbl.Make (struct type t = T.t polyref let equal a b = (a.id = b.id) let hash a = a.id end) module IntHash = PolyHash(struct type t = int end) module BoolHash = PolyHash(struct type t = bool end) The only dificulty with such an approach is that you must use different functions for different hashtables. If you want to define new polymorphic functions using these hashtables, you must again put them in a functor. Regards, Jacques --------------------------------------------------------------------------- Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp JG