* [Caml-list] comparing references
@ 2003-08-11 18:54 Tahir H Butt
2003-08-11 19:25 ` Michal Moskal
0 siblings, 1 reply; 4+ messages in thread
From: Tahir H Butt @ 2003-08-11 18:54 UTC (permalink / raw)
To: caml-list
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. But, is this
comparison as simple as comparing two numbers? 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.
Thanks,
Tahir H Butt
Brown University
Cognitive and Linguistic Sciences
PhD Student
http://www.cog.brown.edu/~tahir
-------------------
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] comparing references
2003-08-11 18:54 [Caml-list] comparing references Tahir H Butt
@ 2003-08-11 19:25 ` Michal Moskal
2003-08-11 19:57 ` Hal Daume III
0 siblings, 1 reply; 4+ messages in thread
From: Michal Moskal @ 2003-08-11 19:25 UTC (permalink / raw)
To: Tahir H Butt; +Cc: caml-list
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] comparing references
2003-08-11 19:25 ` Michal Moskal
@ 2003-08-11 19:57 ` Hal Daume III
2003-08-11 20:02 ` Michal Moskal
0 siblings, 1 reply; 4+ messages in thread
From: Hal Daume III @ 2003-08-11 19:57 UTC (permalink / raw)
To: Michal Moskal; +Cc: Tahir H Butt, caml-list
> > 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.
How much do you need to worry about, ex., the GC moving stuff around and
messing this up?
- Hal
-------------------
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] comparing references
2003-08-11 19:57 ` Hal Daume III
@ 2003-08-11 20:02 ` Michal Moskal
0 siblings, 0 replies; 4+ messages in thread
From: Michal Moskal @ 2003-08-11 20:02 UTC (permalink / raw)
To: Hal Daume III; +Cc: Tahir H Butt, caml-list
On Mon, Aug 11, 2003 at 12:57:46PM -0700, Hal Daume III wrote:
> > > 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.
>
> How much do you need to worry about, ex., the GC moving stuff around and
> messing this up?
You don't need to worry at all. GC moves all references to given object
at once. So comparison results are always the same.
--
: 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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-08-11 20:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-11 18:54 [Caml-list] comparing references Tahir H Butt
2003-08-11 19:25 ` Michal Moskal
2003-08-11 19:57 ` Hal Daume III
2003-08-11 20:02 ` Michal Moskal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox