From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id BAA30579; Fri, 21 May 2004 01:29:46 +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 BAA30542 for ; Fri, 21 May 2004 01:29:45 +0200 (MET DST) Received: from nef.ens.fr (nef.ens.fr [129.199.96.32]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i4KNTiSH021988 for ; Fri, 21 May 2004 01:29:44 +0200 Received: from clipper.ens.fr (clipper-gw.ens.fr [129.199.1.22]) by nef.ens.fr (8.12.11/1.01.28121999) with ESMTP id i4KNTeWT059026 ; Fri, 21 May 2004 01:29:40 +0200 (CEST) Received: from localhost (frisch@localhost) by clipper.ens.fr (8.12.3/jb-1.1) id i4KNTdoc003005 ; Fri, 21 May 2004 01:29:39 +0200 (MET DST) X-Authentication-Warning: clipper.ens.fr: frisch owned process doing -bs Date: Fri, 21 May 2004 01:29:39 +0200 (MET DST) From: Alain Frisch X-X-Sender: frisch@clipper.ens.fr Reply-To: Alain Frisch To: Jon Harrop cc: caml-list@inria.fr Subject: Re: [Caml-list] Hash over ref In-Reply-To: <200405202137.00485.jdh30@cam.ac.uk> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-milter (http://amavis.org/) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-1.3.2 (nef.ens.fr [129.199.96.32]); Fri, 21 May 2004 01:29:40 +0200 (CEST) X-Miltered: at concorde with ID 40AD3F68.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; alain:01 frisch:01 alain:01 frisch:01 caml-list:01 hash:01 hash:01 damien:01 val:01 val:01 struct:01 failwith:01 mutable:01 sig:01 int:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 20 May 2004, Jon Harrop wrote: > Is it possible to hash a ref itself, rather than the object it references? If you really need to use values of type 'a ref (that you create yourself, but need to store in existing data structures), you can cheat and implement Damien suggestion like this: module HashedRef : sig val ref: 'a -> 'a ref val hash: 'a ref -> int end = struct class c = object end type 'a my_ref = { mutable value: 'a; uid : int } let ref x = Obj.magic { value = x; uid = Oo.id (new c) } let hash x = if Obj.size (Obj.repr x) = 2 then (Obj.magic x).uid else failwith "HashedRef.hash: this reference is not hashable" end (Don't do this at home, of course.) -- Alain ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners