This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

RE: [Caml-list] Some things are more equal than others
• Krishnaswami, Neel
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: -- (:) From: Krishnaswami, Neel Subject: RE: [Caml-list] Some things are more equal than others
```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

```