From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 05060BB9C for ; Wed, 23 Nov 2005 20:43:54 +0100 (CET) Received: from ptb-relay03.plus.net (ptb-relay03.plus.net [212.159.14.214]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jANJhr27028586 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Wed, 23 Nov 2005 20:43:53 +0100 Received: from [80.229.56.224] (helo=chetara) by ptb-relay03.plus.net with esmtp (Exim) id 1Ef0X3-0004Q9-57 for caml-list@yquem.inria.fr; Wed, 23 Nov 2005 19:43:53 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Physical compare Date: Wed, 23 Nov 2005 19:38:59 +0000 User-Agent: KMail/1.8.2 References: <4384C0E3.5030300@confluent.org> In-Reply-To: <4384C0E3.5030300@confluent.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200511231938.59745.jon@ffconsultancy.com> X-Miltered: at concorde with ID 4384C679.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 pointers:01 sig:01 val:01 val:01 struct:01 ocaml:01 frog:98 wrote:01 equality:01 integer:01 define:01 define:01 int:01 int:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 On Wednesday 23 November 2005 19:20, Tom Hawkins wrote: > Is their a version of "compare" that is based on physical equality? If > not, how can I define one? Due to the use of a copying collector you cannot define one because the pointers that make up references can change value, i.e. a < b might not remain true for very long. > I need to make a Map where the keys are distinguished by the physical > instance. Tag every key with a unique integer using something like this: module Tag : sig type 'a t val make : 'a -> 'a t val compare : 'a t -> 'a t -> int end = struct type 'a t = int * 'a let i = ref 0 let make x = incr i; !i, x let compare (a, _) (b, _) = compare a b end;; Then use the Tag.compare function to perform physical comparison with a total ordering. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists