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 BAA29637; Thu, 5 Sep 2002 01:20:17 +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 BAA29682 for ; Thu, 5 Sep 2002 01:20:16 +0200 (MET DST) Received: from leia.mandrakesoft.com (office.mandrakesoft.com [195.68.114.34]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g84NKG904254 for ; Thu, 5 Sep 2002 01:20:16 +0200 (MET DST) Received: by leia.mandrakesoft.com (Postfix, from userid 505) id 7A34F4199; Thu, 5 Sep 2002 01:18:19 +0200 (CEST) To: caml-list@inria.fr Subject: [Caml-list] implicit subtyping in method argument and parameterized class From: Pixel Date: 05 Sep 2002 01:18:19 +0200 Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk --=-=-= 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. 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? thanks. Full example: --=-=-= Content-Disposition: attachment; filename=implicit-method-argument-subtyping.ml module Before_ocaml_3_06 = struct class foo = object method foo = () end class foo' = object inherit foo method foo' = () end class on_any_foo = object method with_foo : foo -> unit = fun foo -> foo#foo end class ['foo] on_that_foo = object method with_foo : 'foo -> unit = fun foo -> foo#foo end class on_foo = [foo ] on_that_foo class on_foo' = [foo'] on_that_foo let _ = let foo = new foo in let foo' = new foo' in let on_any_foo = new on_any_foo in let on_foo = new on_foo in let on_foo' = new on_foo' in on_any_foo #with_foo (foo' :> foo) ; (* explicit subtyping *) on_foo #with_foo (foo' :> foo) ; (* explicit subtyping *) on_foo' #with_foo foo' ; () end module Ocaml_3_06 = struct class foo = object method foo = () end class foo' = object inherit foo method foo' = () end class on_any_foo = object method with_foo : 'a. (#foo as 'a) -> unit = fun foo -> foo#foo end class ['foo] on_that_foo = object method with_foo : 'foo -> unit = fun foo -> foo#foo (* could be something like: *) (* method with_foo : 'a. (#'foo as 'a) -> unit = fun foo -> foo#foo *) (* and calling: [foo] on_that_foo *) (* method with_foo : 'a. ('foo as 'a) -> unit = fun foo -> foo#foo *) (* and calling: [#foo] on_that_foo *) end class on_foo = [foo ] on_that_foo class on_foo' = [foo'] on_that_foo let _ = let foo = new foo in let foo' = new foo' in let on_any_foo = new on_any_foo in let on_foo = new on_foo in let on_foo' = new on_foo' in on_any_foo #with_foo foo' ; (* implicit subtyping *) on_foo #with_foo (foo' :> foo) ; (* explicit subtyping *) on_foo' #with_foo foo' ; () end --=-=-= -- programming languages addict http://merd.net/pixel/language-study/ --=-=-=-- ------------------- 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