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 UAA14246; Wed, 20 Aug 2003 20:23:21 +0200 (MET DST) 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 UAA23097 for ; Wed, 20 Aug 2003 20:23:19 +0200 (MET DST) Received: from rabelais.socialtools.net (rabelais.socialtools.net [81.2.94.243]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h7KINIT00039 for ; Wed, 20 Aug 2003 20:23:18 +0200 (MET DST) Received: by rabelais.socialtools.net (Postfix, from userid 108) id B75A923311; Wed, 20 Aug 2003 19:23:17 +0100 (BST) Received: from socialtools.net (chaucer.socialtools.net [81.2.94.242]) by rabelais.socialtools.net (Postfix) with ESMTP id 8B99F2330E; Wed, 20 Aug 2003 19:23:16 +0100 (BST) Message-ID: <3F43BBB8.9090806@socialtools.net> Date: Wed, 20 Aug 2003 19:19:36 +0100 From: Benjamin Geer User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-gb, en, fr, it MIME-Version: 1.0 To: brogoff@speakeasy.net Cc: Brian Hurt , "caml-list@inria.fr" Subject: Re: [Caml-list] does class polymorphism need to be so complicated? References: In-Reply-To: X-Enigmail-Version: 0.76.5.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-2.6 required=5.0 tests=EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, REPLY_WITH_QUOTES,USER_AGENT_MOZILLA_UA,X_ACCEPT_LANG autolearn=ham version=2.54 X-Spam-Checker-Version: SpamAssassin 2.54 (1.174.2.17-2003-05-11-exp) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 brogoff:01 foo:01 int-:01 unit-:01 baz:01 quux:01 val:01 bool:01 inherit:01 mutable:01 speakeasy:01 int:01 unit:03 string:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk brogoff@speakeasy.net wrote: > The extension of Brian's code to rows with more than one field is obvious > though, isn't it? > > type fbbq = > int; bar: unit->string; baz: unit->bool;quux: unit->unit> > > class thing_processor = > object > method do_something (o : fbbq) = > (* do something that calls all those methods *) > method do_something_else (o : fbbq) = > (* do something else that calls all those methods *) > end Unless I've missed something, this only works if none of the classes of type fbbq have any additional methods. Here's an example that doesn't work: type fbbq = int; bar: string; baz: bool; quux: unit > ;; class thing x_init = object (self) val mutable x = x_init method foo y = x + y method bar = string_of_int (self#foo 2) method baz = (x = 1) method quux = print_string (string_of_int x) end;; class extra_thing x_init = object (self) inherit thing x_init method quuux = self#quux; self#quux end;; class thing_processor = object method process (obj : fbbq) = obj#quux; print_string (string_of_int (obj#foo 1)); print_string obj#bar; print_string (string_of_bool obj#baz) end ;; let et = new extra_thing 1 ;; let tp = new thing_processor ;; tp#process et ;; The call to 'process' produces the following error: This expression has type extra_thing = < bar : string; baz : bool; foo : int -> int; quuux : unit; quux : unit > but is here used with type fbbq = < bar : string; baz : bool; foo : int -> int; quux : unit > Only the first object type has a method quuux So this approach doesn't fit the requirement, which is to be able to use a derived class anywhere its base class can be used. Ben ------------------- 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