operational semantics of = for objects

From: Sorin Stratulat (Sorin.Stratulat@loria.fr)
Date: Thu Mar 26 1998 - 18:32:49 MET


Date: Thu, 26 Mar 1998 18:32:49 +0100
From: Sorin Stratulat <Sorin.Stratulat@loria.fr>
To: caml-list@inria.fr
Subject: operational semantics of = for objects

Hello !

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.

Here you have two examples where I mainly created a class and some
instances that are further compared:

example 1 ------------
        Objective Caml version 1.07

# class point x_init =
  val mutable x = x_init
  method get_x = x
          method move d = x <- x + d
  end;;
class point (int) =
  val mutable x : int
  method get_x : int
  method move : int -> unit
end
# let p = new point 7;;
val p : point = <obj>
# let q = new point 7;;
val q : point = <obj>
# p=q;;
- : bool = false
# List.mem (new point 7) [p;q];;
- : bool = false
# let r = p;;
val r : point = <obj>
# p=r;;
- : bool = true
#

example 2 -----------------
        Objective Caml version 1.05

# class point x_init =
  val mutable x = x_init
  method get_x = x
          method move d = x <- x + d
  end;;
        class point (int) =
  val mutable x : int
  method get_x : int
  method move : int -> unit
end
# let p = new point 7;;
val p : point = <obj>
# let q = new point 7;;
val q : point = <obj>
# p=q;;
- : bool = true
# List.mem (new point 7) [p;q];;
- : bool = true
# let r = p;;
val r : point = <obj>
# p = r;;
- : bool = true
#

Thank you,

Sorin

-- 
e-mail : Sorin.Stratulat@loria.fr
Project: PROTHEO
Office : A201                             | Home:
------                                    | ------
tel:  03.83.59.30.02                      | C.U. du Placieux, ch. 1128
LORIA - BP 239                            | Bd. Mare'chal Lyautey
F-54506 VANDOEUVRE-les-NANCY Cedex FRANCE | 54600 Villers-le`s-Nancy



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:14 MET