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 GAA22530; Fri, 22 Aug 2003 06:00:03 +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 GAA02301 for ; Fri, 22 Aug 2003 06:00:01 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h7M3xxf20198 for ; Fri, 22 Aug 2003 06:00:00 +0200 (MET DST) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3p2/3.7W) with ESMTP id MAA28916; Fri, 22 Aug 2003 12:59:54 +0900 (JST) To: ben@socialtools.net Cc: caml-list@inria.fr Subject: Re: [Caml-list] does class polymorphism need to be so complicated? In-Reply-To: <3F455730.2030407@socialtools.net> References: <3F452978.1040805@socialtools.net> <3F455730.2030407@socialtools.net> X-Mailer: Mew version 1.94.2 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20030822125953S.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 22 Aug 2003 12:59:53 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 jacques:01 unification:01 jacques:01 curiously:01 monomorphic:01 ocaml:01 remy:01 garrigue:01 garrigue:01 pottier:01 polymorphic:01 compile:02 string:03 string:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Benjamin Geer > Benjamin Geer wrote: > > I'm still curious to know why the example I gave (returning a > > mysql_connection from a method that was typed to return a #connection) > > didn't compile, though ("This method has type string -> mysql_connection > > which is less general than 'a. string -> (#connection as 'a)"). Because #connection is _not_ an interface. It is just a polymorphic type including all types having more methods than connection. So returning a #connection means that the returned object already has all the methods in the world, with all types imaginable. Nonsense. #connection only makes sense on the left-hand side of an arrow. By the way, the typing of #connection really uses rows (as by Remy and later Pottier), but in a simplified way. So the unification Jacques Carrette is talking about is already there from the beginning of ocaml. > Curiously, it works if the class is parameterised instead of the method: > > class type ['a] driver = > object > constraint 'a = #connection > method get_connection : db_name:string -> 'a > end > > class mysql_driver = > object (self : 's) > constraint 's = #connection #driver > method get_connection ~(db_name:string) = > new mysql_connection db_name > end The meaning is completely different. Your class type says that get_connection must at least have all methods of connection. But in mysql_driver, you end up with a get_connection returning a (monomorphic) mysql_connection. No progress whatsoever. Jacques Garrigue ------------------- 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