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 BAA18306; Thu, 21 Aug 2003 01:44:43 +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 BAA25132 for ; Thu, 21 Aug 2003 01:44:42 +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 h7KNieT17410 for ; Thu, 21 Aug 2003 01:44:41 +0200 (MET DST) Received: by rabelais.socialtools.net (Postfix, from userid 108) id 0F57523311; Thu, 21 Aug 2003 00:44:39 +0100 (BST) Received: from socialtools.net (chaucer.socialtools.net [81.2.94.242]) by rabelais.socialtools.net (Postfix) with ESMTP id B5DE82330E; Thu, 21 Aug 2003 00:44:37 +0100 (BST) Message-ID: <3F440702.8040704@socialtools.net> Date: Thu, 21 Aug 2003 00:40:50 +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: "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.1 required=5.0 tests=EMAIL_ATTRIBUTION,IN_REP_TO,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 subtyping:01 library's:01 coercions:01 ocaml:01 coerce:01 speakeasy:01 interfaces:01 polymorphic:01 syntax:02 implicit:02 cumbersome:02 classes:03 wrote:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk brogoff@speakeasy.net wrote: > Yes, OCaml doesn't have implicit subtyping. [...] > If you want to solve your problem, you'll need to coerce, and you > can solve it fairly simply by replacing the troublesome line below with one of > the following > > tp#process (et :> fbbq) ;; > > or > > let proc o = (new thing_processor)#process (o :> fbbq);; > proc et;; I've thought some more about this idea of wrapper functions, and actually, it doesn't seem simple at all. In an object-oriented program, *all* methods are potentially polymorphic; this is what makes object orientation useful. It means that you can always pass, to a method in class C, an instance of a class that didn't exist yet when C was written. A library's author therefore doesn't need to anticipate all the classes that will ever use the library. If you used wrapper functions to do coercions, you would need a wrapper function for every method in the program. This would be extremely cumbersome and ugly, and hardly object-oriented. Doing coercions at the call site is equally cumbersome, and you lose the ability to change the method so that it accepts a less derived class. It seems to me that the idea of interfaces (class types) is quite powerful, and would be a good solution, if only the syntax for using them in method definitions were not so complicated. 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