From: Jacques GARRIGUE <garrigue@kurims.kyoto-u.ac.jp>
To: Sorin.Stratulat@loria.fr
Cc: caml-list@inria.fr
Subject: Re: operational semantics of = for objects
Date: Fri, 27 Mar 1998 21:14:25 +0900 [thread overview]
Message-ID: <19980327211425D.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: Your message of "Thu, 26 Mar 1998 18:32:49 +0100" <351A9141.3D52@loria.fr>
From: Sorin Stratulat <Sorin.Stratulat@loria.fr>
> After comparing the results of the code (see below) executed on
> different versions of OCAML (1.05 and 1.07), I would like to know if
> anybody can explain me how the equality operator works for objects (if
> it is possible in both versions). As I understood from a previous
> message, overloading the operators is not supported yet.
The fastest way to understand what has changed is to have a look at
oo.ml in the standard library. In 1.07, all objects have an oid,
unique to them, like in many object-oriented languages, and as a
result structural equality (=) will always give them different.
That is
let o1 = new c ()
and o2 = new c ()
in o1 = o2;;
- : bool = false
let o1 = new c () in
let o2 = Oo.copy o1 in
o1 = o2;;
- : bool = false
let o1 = new c () in
let o2 = o1 in
o1 = o2;;
- : bool = true
What you must understand is that the last example does not define two
objects but only two names for the same object, and this is why they
are equal.
In 1.05 there was no oid (I suppose), so two objects would be equal
when their instance variables are equal. This may look nice, but there
are several drawbacks:
* if there are functions stored in instance variables, trying to
compare two objects would raise an exception.
* even if instance variables are equal, there are still ways to
distinguish two objects (particularly if they have mutable
instance variables), so you cannot consider them as rigorously
equal.
Jacques
---------------------------------------------------------------------------
Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp
<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>
next prev parent reply other threads:[~1998-03-27 15:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-03-26 17:32 Sorin Stratulat
1998-03-27 12:14 ` Jacques GARRIGUE [this message]
1998-03-27 14:33 ` Jerome Vouillon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=19980327211425D.garrigue@kurims.kyoto-u.ac.jp \
--to=garrigue@kurims.kyoto-u.ac.jp \
--cc=Sorin.Stratulat@loria.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox