From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA31461 for caml-redistribution; Fri, 27 Mar 1998 16:34:57 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id NAA08812 for ; Fri, 27 Mar 1998 13:14:05 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.8.7/8.8.5) with ESMTP id NAA06062 for ; Fri, 27 Mar 1998 13:13:58 +0100 (MET) Received: from localhost (safran.kurims.kyoto-u.ac.jp [130.54.16.91]) by kurims.kurims.kyoto-u.ac.jp (8.8.8/3.6W) with ESMTP id VAA27923; Fri, 27 Mar 1998 21:13:30 +0900 (JST) To: Sorin.Stratulat@loria.fr Cc: caml-list@inria.fr Subject: Re: operational semantics of = for objects In-Reply-To: Your message of "Thu, 26 Mar 1998 18:32:49 +0100" <351A9141.3D52@loria.fr> References: <351A9141.3D52@loria.fr> X-Mailer: Mew version 1.92 on Emacs 20.2 / Mule 3.0 (MOMIJINOGA) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <19980327211425D.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 27 Mar 1998 21:14:25 +0900 From: Jacques GARRIGUE X-Dispatcher: imput version 971024 Sender: weis From: Sorin Stratulat > 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 JG