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 VAA18409; Mon, 11 Aug 2003 21:27:38 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA19356 for ; Mon, 11 Aug 2003 21:27:37 +0200 (MET DST) Received: from ep09.kernel.pl (ep09.kernel.pl [212.87.11.162]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h7BJRZT21442 for ; Mon, 11 Aug 2003 21:27:36 +0200 (MET DST) Received: (qmail 21028 invoked by uid 566); 11 Aug 2003 19:27:33 -0000 Date: Mon, 11 Aug 2003 21:25:52 +0200 From: Michal Moskal To: Tahir H Butt Cc: caml-list@inria.fr Subject: Re: [Caml-list] comparing references Message-ID: <20030811192552.GA8711@roke.freak> Mail-Followup-To: Tahir H Butt , caml-list@inria.fr References: <1060628087.11843.16.camel@venere.cog.brown.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1060628087.11843.16.camel@venere.cog.brown.edu> User-Agent: Mutt/1.4.1i X-PGP-Fingerprint: CF89 1B14 11BE 1CC9 2CA3 7497 5E32 69B4 BC71 B4C2 X-AntiVirus: scanned for viruses by AMaViS 0.2.1 (http://amavis.org/) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; michal:01 moskal:01 malekith:01 pld-linux:01 caml-list:01 0400,:01 butt:99 implemented:01 traversing:01 cyclic:01 kernel:01 equality:01 int:01 comparison:02 compares:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, Aug 11, 2003 at 02:54:47PM -0400, Tahir H Butt wrote: > I don't know for sure, so I decided to ask around. My question is this: > given two references, when one compares them, is it just the addressing > which is examined, or the actual content? For instance: > > type symbol = Symbol of int > let a = ref (Symbol 1) in > let b = ref (Symbol 2) in > let c = ref (Symbol 1) in > .... > > upon inspection, a=c -> true, and a=b -> false, as desired. = does structural equality. As ref is implemented as record type, there is nothing that would prevent = from traversing entire ref-ed data structure. > But, is this > comparison as simple as comparing two numbers? It can take more time. It is even possible it won't stop on cyclic data structures. > I ask because my sum > types can be big (I'm dealing with trees), so it would be good if when I > want to check if two trees are the same, all I need to do is look at the > references to them. Use == if you want to compare addresses. -- : Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv : When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h ------------------- 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