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 QAA13799; Thu, 20 Nov 2003 16:53:35 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 QAA13837 for ; Thu, 20 Nov 2003 16:53:34 +0100 (MET) Received: from mail.npc.de (fw.npc.de [62.225.140.214]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hAKFrX119785 for ; Thu, 20 Nov 2003 16:53:33 +0100 (MET) Received: from styx.ffm.npc.de (lion.npc.de [192.168.129.1]) by mail.npc.de (Postfix) with ESMTP id 5A467108B; Thu, 20 Nov 2003 16:53:32 +0100 (CET) Received: from hera.ffm.npc.de (hera.ffm.npc.de [192.168.130.8]) by styx.ffm.npc.de (Postfix STYX NPC GmbH) with ESMTP id 139F2C437; Thu, 20 Nov 2003 16:53:31 +0100 (CET) Received: from ares.ffm.npc.de (ares.ffm.npc.de [192.168.130.32]) by hera.ffm.npc.de (Postfix HERA NPC GmbH) with ESMTP id 92FD2159E5; Thu, 20 Nov 2003 16:53:30 +0100 (CET) Received: from ares.ffm.npc.de (ares.ffm.npc.de [192.168.130.32]) by ares.ffm.npc.de (Postfix ARES NPC GmbH) with ESMTP id B8E09183C; Thu, 20 Nov 2003 16:53:29 +0100 (CET) Subject: Re: [Caml-list] classes, objects, and class variables From: Gerd Stolpmann To: Jacques Garrigue Cc: caml-list@inria.fr In-Reply-To: <20031120220714O.garrigue@kurims.kyoto-u.ac.jp> References: <20031120220714O.garrigue@kurims.kyoto-u.ac.jp> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 20 Nov 2003 16:53:28 +0100 Message-Id: <1069343609.19408.20.camel@ares> Mime-Version: 1.0 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 gerd:01 stolpmann:01 jacques:01 dynamically:01 prerr:01 endline:01 prerr:01 endline:01 gerd:01 stolpmann:01 viktoriastr:01 64293:01 darmstadt:01 semantics:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Am Don, 2003-11-20 um 14.07 schrieb Jacques Garrigue: > To whom it may concern, > > I'm in the process of improving the ocaml class system. > Principally the following two points: > 1) making class creation cheaper. > If you believed you could create classes in a "let module", and > get away with it, you weere: it was prohibitively expensive in both > time and space. Now I'm seeing 10000% speeups. > 2) using this to make objects (or final classes) first class. > Be able to write "let o = object (self) method m = ... end" > Side advantage, there are no restrictions on polymorphism. > > But in this process, I came along with the rather strange behaviour of > class variables. Class variables are defined by a let before any > parameters, for instance > class c = let a = init () in fun ... -> object ... end > Their current semantics is to be evaluated repeatedly, once for c, > but again for all classes inheriting from c. The problem is that this > is costly for the implementation, doesn't fit well with the > possibility to create dynamically an arbitrary number of classes > inheriting from, and that I don't see what it's intended for. > > So I'm planning to revert to the more intuitive semantics: evaluation > when creating c, but never again. > > Does that bother anybody? Just experimenting (to understand what you mean, I never discovered this "feature" myself): - Classes without arguments: # class x = let _ = prerr_endline "X" in object end;; X class x : object end # class y = let _ = prerr_endline "Y" in object inherit x end;; X Y class y : object end - Classes with arguments: # class x() = let _ = prerr_endline "X" in object end;; class x : unit -> object end # class y() = let _ = prerr_endline "Y" in object inherit x() end;; class y : unit -> object end # new x();; X - : x = # new y();; Y X - : y = I suppose you are only referring to the case where classes do not have arguments (because in the other case, the class variables can be dependent on class arguments, so they must be evaluated again for every subclass). I'm quite surprised that the class variables are evaluated in the reverse order in the argument-less case. This seems to be an inconsistency anyway, so I guess this is a rarely used feature. (When "inherit" is read as an _instruction_ to initialize the named class again for usage in the subclass, the order of evaluation should be the same as in the case with arguments.) If somebody needs repeated evaluation, he can add unit arguments to the class definition. So my conclusion is: do it. Gerd -- ------------------------------------------------------------ Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de ------------------------------------------------------------ ------------------- 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