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 PAA22365; Thu, 21 Aug 2003 15:42:21 +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 PAA21353 for ; Thu, 21 Aug 2003 15:42:19 +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 h7LDgIf11827 for ; Thu, 21 Aug 2003 15:42:18 +0200 (MET DST) Received: by rabelais.socialtools.net (Postfix, from userid 108) id 0A18923314; Thu, 21 Aug 2003 14:42:17 +0100 (BST) Received: from socialtools.net (chaucer.socialtools.net [81.2.94.242]) by rabelais.socialtools.net (Postfix) with ESMTP id DC88C23311; Thu, 21 Aug 2003 14:42:16 +0100 (BST) Message-ID: <3F44CB52.3040207@socialtools.net> Date: Thu, 21 Aug 2003 14:38:26 +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: Jacques Garrigue Cc: caml-list@inria.fr Subject: Re: [Caml-list] does class polymorphism need to be so complicated? References: <3F43E250.1040903@socialtools.net> <20030821092849B.garrigue@kurims.kyoto-u.ac.jp> <3F448015.8090106@socialtools.net> <20030821175808V.garrigue@kurims.kyoto-u.ac.jp> In-Reply-To: <20030821175808V.garrigue@kurims.kyoto-u.ac.jp> 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 jacques:01 api:01 val:01 caml:01 garrigue:01 unit:03 string:03 wrote:03 obj:03 inheritance:03 object:03 complicated:04 rejects:05 confusing:05 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Jacques Garrigue wrote: > OK, there's also another way to do it, without inheritance. I just > tried not to be confusing. > > class type printer = object > method virtual print : #printable -> unit > end > > class my_printer () = object (self : #printer) > method print obj = ... > end I've just tried a little experiment with this, and it doesn't seem to work in the case I had in mind: (* A simple API *) class type connection = object method close : unit end ;; class type driver = object method get_connection : string -> #connection end ;; (* An implementation of the API *) class mysql_connection db_name = object (self : 's) constraint 's = #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 (self : 's) constraint 's = #driver method get_connection db_name = new mysql_connection db_name end;; Caml rejects the definition of 'get_connection' in 'mysql_driver': This method has type string -> mysql_connection which is less general than 'a. string -> (#connection as 'a) 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