From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA05327; Fri, 4 Oct 2002 18:53:01 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA05415 for ; Fri, 4 Oct 2002 18:53:00 +0200 (MET DST) Received: from wetware.wetware.com (wetware.wetware.com [199.108.16.1]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g94Gqx502604 for ; Fri, 4 Oct 2002 18:52:59 +0200 (MET DST) Received: from wetware.com(ra02.wetware.com[199.108.16.82]) (2234 bytes) by wetware.wetware.com via sendmail with P:esmtp/R:bind_hosts/T:inet_zone_bind_smtp (sender: ) id for ; Fri, 4 Oct 2002 09:52:58 -0700 (PDT) (Smail-3.2.0.114 2001-Aug-6 #1 built 2002-Sep-2) Date: Fri, 4 Oct 2002 09:52:59 -0700 Subject: Re: [Caml-list] Oo.id Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v546) Cc: The Trade To: Jacques Garrigue From: james woodyatt In-Reply-To: <20021004165824H.garrigue@kurims.kyoto-u.ac.jp> Message-Id: Content-Transfer-Encoding: 7bit X-Mailer: Apple Mail (2.546) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Friday, Oct 4, 2002, at 00:58 US/Pacific, Jacques Garrigue wrote: > From: james woodyatt >> Reading the source code in the caml distribution really didn't help me >> understand what's going on, so I'm asking the list again: >> >> Why does every class object contain field with unique integer? > > [...] > So we had to add a unique id to each object, which is used for > primitive equality and comparison functions. This also seemed > reasonable to make it available to the user, for use in indexed data > structures. Wow. Okay, I just tried some stuff out: > [kallisti:~] jhw% ocaml > Objective Caml version 3.06 > > # class foo = object method foo = () end;; > class foo : object method foo : unit end > # let a = new foo and b = new foo;; > val a : foo = > val b : foo = > # a < b;; > - : bool = true > # b < a;; > - : bool = false This is one of those interesting little oddities in Objective Caml that is really not apparent from reading the documentation. Thanks for explaining it. One suggestion: it might help to have a brief discussion of Oo.id in the tutorial about advanced uses of classes and modules. I would put it into the section about the subject/observer pattern. Since objects all have unique identifiers, the subject could use a map of identifiers to observers rather than a list of observers. This would allow you to easily write a remove_observer method that didn't have to iterate over the whole list. -- j h woodyatt markets are only free to the people who own them. ------------------- 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