Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] comparing references
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Michal Moskal <malekith@p...>
Subject: Re: [Caml-list] comparing references
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