Browse thread
[Caml-list] Semantics of physical equality
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Andreas Rossberg <AndreasRossberg@w...> |
| Subject: | Re: [Caml-list] Semantics of physical equality |
Michal Moskal <malekith@pld-linux.org> wrote:
> > type test =
> > {
> > mutable a:int;
> > b:int
> > };;
> >
> > let r = {a=0;b=2};;
> >
> > let x = r and y = r in
> > assert((x.a==y.a)&&(x.b==y.b)&&(x==y))
> > ;;
> >
> > Does this always ok ?
>
> Yes, of course. The objects x and y are physically equal (which implies
> physical equality of their fields).
No, because (x.a == x.a) is not comparing the fields themselves (you cannot
do that, fields are not first class), but the projected values. They may be
physically different. Consider:
type r = {mutable a : float}
let r = {a = 1.0}
let b = x.a == x.a
This will deliver false.
> But both r.a and r.b are ints, so it is always OK (== and = are the same
> on ints).
That is what the current implementation does, but it is not guaranteed.
- Andreas
-------------------
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