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 DAA30947; Thu, 5 Sep 2002 03:03:36 +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 DAA30937 for ; Thu, 5 Sep 2002 03:03:35 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g8513X907636 for ; Thu, 5 Sep 2002 03:03:34 +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.3/3.7W) with ESMTP id KAA00931; Thu, 5 Sep 2002 10:02:44 +0900 (JST) To: pixel@mandrakesoft.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] implicit subtyping in method argument and parameterized class In-Reply-To: References: 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: <20020905100244U.garrigue@kurims.kyoto-u.ac.jp> Date: Thu, 05 Sep 2002 10:02:44 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Pixel > With ocaml 3.06 we are now able to replace > > method with_foo : foo -> unit = ... > with > method with_foo : 'a. (#foo as 'a) -> unit = ... > > and get implicit subtyping when calling with_foo. Note that this implicit subtyping is essentially width-subtyping (the object passed may have more methods), but not full subtyping (the methods may not have subtypes). > But I can't make it work when "foo" is a parametric variable: > > method with_foo : 'foo -> unit = ... > works whereas > method with_foo : 'a. (#'foo as 'a) -> unit = ... > gives "Syntax error", and > method with_foo : 'a. ('foo as 'a) -> unit = ... > gives "This type has no row variable" > > Is there a solution? No. Class parameters are just type variables. You can unify them, but no more. ('foo as 'a) is equivalent to 'foo constraint 'a = 'foo. Note also that since the scope of 'a is the whole method type, this doesn't make sense from a typing point of view. What might make sense is: class ['with_foo] on_that_foo with_foo = object method with_foo : 'with_foo = with_foo end let o = new on_that_foo (fun x -> x#foo : 'a. (#some_foo as 'a) -> unit) But this would require first class polymorphic functions, which are not yet in the language. And if you want to share the code in the class, you would also need subtyping between explicitly polymorphic types, which is not there either. Jacques ------------------- 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