caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Some things are more equal than others
@ 2001-11-08 18:34 Jim Farrand
  2001-11-08 18:46 ` Will Benton
  0 siblings, 1 reply; 3+ messages in thread
From: Jim Farrand @ 2001-11-08 18:34 UTC (permalink / raw)
  To: caml-list


Silly newbie question coming up...

What's the difference between (=) and (==)?

I know that this is almost certainly a case of RTFM, but I can't seem to find 
the right place.  6.7.4 mentions "structural" and "physical" equality, but 
doesn't define either.

My guess is that "physical" equality is "are these the same object", and 
structural equality is "are these objects equivelent".  Hence:

# "Jim"=="Jim";;
- : bool = false
# "Jim"="Jim";;
- : bool = true€

I thought I'd better check I'm guessing right, or I will almost certainly 
fall over this sometime in the future.  :)

TIA,
Jim
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Some things are more equal than others
  2001-11-08 18:34 [Caml-list] Some things are more equal than others Jim Farrand
@ 2001-11-08 18:46 ` Will Benton
  0 siblings, 0 replies; 3+ messages in thread
From: Will Benton @ 2001-11-08 18:46 UTC (permalink / raw)
  To: caml-list

On Thu, 2001-11-08 at 12:34, Jim Farrand wrote:

> I know that this is almost certainly a case of RTFM, but I can't seem to find 
> the right place.  6.7.4 mentions "structural" and "physical" equality, but 
> doesn't define either.

Someone on the list will correct me if I'm wrong, but to clarify your
guess (which seems correct to me):  Physical equality is a pointer
comparison -- i.e. "do these objects occupy the same memory location".
I have assumed that, by "Structural equality", they mean *shallow*
equivalence -- i.e. "do these objects have the same structure, but not
necessarily the same content".  Is this correct?




wb

-- 
Will Benton      | "Nicht wie die Welt ist, ist das Mystische, 
willb@acm.org    |  sondern daß sie ist." --L. Wittgenstein
**GnuPG public key:  http://www.cs.wisc.edu/~willb/pubkey

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [Caml-list] Some things are more equal than others
@ 2001-11-08 19:16 Krishnaswami, Neel
  0 siblings, 0 replies; 3+ messages in thread
From: Krishnaswami, Neel @ 2001-11-08 19:16 UTC (permalink / raw)
  To: 'Will Benton', caml-list

Will Benton [mailto:willb@cs.wisc.edu] wrote:
> On Thu, 2001-11-08 at 12:34, Jim Farrand wrote:
> > I know that this is almost certainly a case of RTFM, but I 
> > can't seem to find the right place.  6.7.4 mentions "structural" and 
> > "physical" equality, but doesn't define either.
> 
> Someone on the list will correct me if I'm wrong, but to clarify your
> guess (which seems correct to me):  Physical equality is a pointer
> comparison -- i.e. "do these objects occupy the same memory location".

This is correct. (The one filip is that for unboxed integers the
requirement is that the bit pattern in the words be the same, since 
they aren't pointers.)

> I have assumed that, by "Structural equality", they mean *shallow*
> equivalence -- i.e. "do these objects have the same structure, but not
> necessarily the same content".  Is this correct?

This is not so. Eg, 

# [1, 2, 3] = [1, 2, 3];;
- : bool = true;

# [1, 2, 3] = [1, 2, 8];;
- : bool = false;

What (=) does is rather like the Scheme equal? predicate. It 
walks down the structure of the two objects you are comparing, 
and makes sure that the whole thing is equal. This means that
you can trick it into hanging with recursive structures:

type foo = Foo of foo

let rec x = Foo x
let rec y = Foo y

Then the expression (x = y) will not terminate, since the (=)
predicate will loop as it chases pointers infinitely.


--
Neel Krishnaswami
neelk@cswcasa.com
 
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-11-08 19:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-08 18:34 [Caml-list] Some things are more equal than others Jim Farrand
2001-11-08 18:46 ` Will Benton
2001-11-08 19:16 Krishnaswami, Neel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).