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 SAA18569; Wed, 20 Aug 2003 18:29:39 +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 SAA14698 for ; Wed, 20 Aug 2003 18:29:38 +0200 (MET DST) Received: from rabelais.socialtools.net (rabelais.socialtools.net [81.2.94.243]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h7KGTbf27731 for ; Wed, 20 Aug 2003 18:29:37 +0200 (MET DST) Received: by rabelais.socialtools.net (Postfix, from userid 108) id A99FD23311; Wed, 20 Aug 2003 17:29:36 +0100 (BST) Received: from socialtools.net (chaucer.socialtools.net [81.2.94.242]) by rabelais.socialtools.net (Postfix) with ESMTP id 62CEC2330E; Wed, 20 Aug 2003 17:29:35 +0100 (BST) Message-ID: <3F43A115.6080201@socialtools.net> Date: Wed, 20 Aug 2003 17:25:57 +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: Brian Hurt Cc: 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 unit-:01 upcast:01 foo:01 int-:01 baz:01 quux:01 shorthand:01 alas:01 bool:01 caml:01 int:01 coercion:01 declaring:01 cumbersome:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Brian Hurt wrote: > Instead of declaring obj to be printable, why not just declare that it has > a function print? Like: > > class printer = > object > method print (obj: unit>) = obj#print (); > end;; > > This removes the need for a coercion, as it gets around the need to > upcast. That's pretty cumbersome, because it will have to be repeated for every method that uses an object of that type. And suppose you need the method's argument to be an object with several methods. You could end up writing methods like this: class thing_processor = object method do_something (t : obj: int; bar: unit->string; baz: unit->bool ; quux: unit->unit>) = (* do something that calls all those methods *) method do_something_else (t : obj: int; bar: unit->string; baz: unit->bool; quux: unit->unit>) = (* do something else that calls all those methods *) end;; It would seem natural to define an interface as a shorthand, and to use it like this: class type thing = object method foo : int -> int method bar : string method baz : bool method quux : unit end;; class thing_processor = object method do_something (t : #thing) = (* do something that calls all those methods *) method do_something_else (t : #thing) = (* do something that calls all those methods *) end;; But alas, this is not valid in Caml. 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