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 UAA28809; Thu, 21 Aug 2003 20:05:01 +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 UAA29666 for ; Thu, 21 Aug 2003 20:04:59 +0200 (MET DST) Received: from mail.speakeasy.net (mail13.speakeasy.net [216.254.0.213]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h7LI4wT22091 for ; Thu, 21 Aug 2003 20:04:58 +0200 (MET DST) Received: (qmail 2261 invoked from network); 21 Aug 2003 18:04:56 -0000 Received: from unknown (HELO grace.speakeasy.org) ([216.254.0.2]) (envelope-sender ) by mail13.speakeasy.net (qmail-ldap-1.03) with DES-CBC3-SHA encrypted SMTP for ; 21 Aug 2003 18:04:56 -0000 Date: Thu, 21 Aug 2003 11:04:56 -0700 (PDT) From: brogoff@speakeasy.net To: Benjamin Geer cc: Jacques Garrigue , "caml-list@inria.fr" Subject: Re: [Caml-list] does class polymorphism need to be so complicated? In-Reply-To: <3F449301.8050500@socialtools.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Loop: caml-list@inria.fr X-Spam: no; 0.00; brogoff:01 caml-list:01 downcast:01 passing:01 api:01 api:01 val:01 coerce:01 inherit:01 inherit:01 speakeasy:01 coercion:01 objects:02 unit:03 string:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 21 Aug 2003, Benjamin Geer wrote: > Alternatively, you could use a virtual base class 'connection', and > always downcast the implementing class before passing it to application > code. But this places an additional burden on the library author. I think the burden is very slight, but I have no problem at all with using functions outside of objects. Realistic implementations would provide coercion functions for every base class you want to coerce to, perhaps named something like "as_base_class_name". Using the exmaple you give in another message, we get something like this (* A simple API *) class virtual connection = object method virtual close : unit end ;; class virtual driver = object method virtual get_connection : string -> connection end ;; let as_connection o = (o : #connection :> connection);; (* An implementation of the API *) class mysql_connection db_name = object inherit connection val _db_name = db_name method close = print_string "closing connection "; print_string _db_name; print_newline(); (* An extra method, which could be used by the driver *) method get_status = "OK" end ;; class mysql_driver = object inherit driver method get_connection db_name = as_connection (new mysql_connection db_name) end;; which doesn't seem bad compared to your original desired code. -- Brian ------------------- 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