Browse thread
multiple inheritance, bug or feature ?
[
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: | Oliver Bandel <oliver@f...> |
| Subject: | Re: [Caml-list] multiple inheritance, bug or feature ? |
On Sat, Feb 25, 2006 at 12:01:00PM +0100, sejourne_kevin wrote: > Hello : > > > Consider the following sample : > > class a = > object > val mutable x = 0 > method set v = Printf.printf "%d\n" x;x <- v > end > ;; [...] > class c : > object > val mutable x : int > val mutable y : int > method set : int -> unit > method set_x_a : int -> unit > method set_x_a' : int -> unit > method set_y : int -> unit > end > > let d = new c;; > val d : c = <obj> > > d#set_x_a 3;; > 0 > - : unit = () > > d#set_x_a' 2;; > 0 > - : unit = () > > > When I wrote this program I expect this behavior but > according to the warnings M the result should be 3. Why do you think the expected behaviour should be printing the 3? Your method prints the old value, not the new value. ======================= # let o = new c;; val o : c = <obj> # o#set_x_a 10;; 0 - : unit = () # o#set_x_a 20;; 10 - : unit = () # o#set_x_a 30;; 20 - : unit = () # ======================= If you want to print the current value after update, you should also write your code in the way it it does this. So, you should write it in this way: method set v = x <- v; Printf.printf "%d\n" x Ciao, Oliver