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 CAA06519; Thu, 13 Mar 2003 02:57:04 +0100 (MET) 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 CAA06533 for ; Thu, 13 Mar 2003 02:57:03 +0100 (MET) 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 h2D1v2f08942 for ; Thu, 13 Mar 2003 02:57:02 +0100 (MET) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id KAA23723; Thu, 13 Mar 2003 10:56:56 +0900 (JST) To: Damien.Pous@ens-lyon.fr Cc: caml-list@pauillac.inria.fr Subject: Re: [Caml-list] polymorphic methods In-Reply-To: <20030313000716.3e6bb57c.Damien.Pous@ens-lyon.fr> References: <20030313000716.3e6bb57c.Damien.Pous@ens-lyon.fr> 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: <20030313105656R.garrigue@kurims.kyoto-u.ac.jp> Date: Thu, 13 Mar 2003 10:56:56 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) X-Spam: no; 0.00; jacques:01 caml-list:01 damien:01 ens-lyon:01 quantified:01 unify:01 dummy:01 ocaml:01 garrigue:01 polymorphic:01 abbreviation:02 recurse:02 essentially:02 clearer:02 unit:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Damien > Does someone know why the following class type > is not accepted ? > > # class type a = object method m: 'a. (#a as 'a) -> unit end;; > The abbreviation #a expands to type #a but is used with type < .. > Essentially because the type abbreviation #a is not yet fully defined when its methods are typed. So what is happening here is that the type uses a first definition of #a, with no methods at all, and then tries to unify it with the real #a, with a method m, and fails because the first one is supposed to be polymorphic. I admit the error message could be clearer, but polymorphic methods are a recent addition to ocaml, and it is really hard to give proper error messages for their definitions. Now, the serious part: can such a type be defined? After working a bit on this riddle, I'm afraid the answer is no. The reason is that there is no way to recurse on a quantified polymorphic method rather than on the whole object. The closest I found is: class type a = object method m : < d : 'b. (< m : 'a; .. > as 'b) -> unit > as 'a end The dummy wrapper is just there to allow one to recurse on the polymoprhic method itself. You can call the method m by doing [a#m#d a'] in place of [a#m a']. Thank you for pointing at this interesting phenomenon. 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