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 AAA31565; Thu, 22 Aug 2002 00:58:18 +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 AAA31526 for ; Thu, 22 Aug 2002 00:58:18 +0200 (MET DST) Received: from favie.faith.gr.jp (favie.faith.gr.jp [61.127.175.250]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g7LMwF923775 for ; Thu, 22 Aug 2002 00:58:16 +0200 (MET DST) Received: from localhost (dhcp7.faith.gr.jp [192.168.1.17]) by favie.faith.gr.jp (8.9.3/8.9.3) with ESMTP id HAA21080; Thu, 22 Aug 2002 07:57:58 +0900 To: nadji@noos.fr Cc: caml-list@inria.fr Subject: Re: [Caml-list] polymorphic method question In-Reply-To: <3D640AF1.C24688A@noos.fr> References: <3D640AF1.C24688A@noos.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: <20020822075744N.garrigue@kurims.kyoto-u.ac.jp> Date: Thu, 22 Aug 2002 07:57:44 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: nadji@noos.fr > I am puzzled by this behaviour, can a guru explain me ? > I have two classes [...] > I want to do a class gentoto : > class gentoto = object > method gen : 'a . 'a -> 'a basic = > fun x -> (new toto x :> 'a basic ) > end;; > But the compiler complains that : > Characters 64-98: > fun x -> (new toto x :> 'a basic ) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > This method has type 'a -> 'a basic which is less general than > 'b. 'b -> 'b basic > > ... but if I do : > let newtotoasbasic x = (new toto x :> 'a basic );; [...] > The compiler agrees with me ... > What is wrong with the first declaration ? There is a problem with the scoping of named type variables in the language, which makes them incompatible with polymorphic methods. You can solve this by using anonymous variables: # class gentoto = object method gen : 'a . 'a -> 'a basic = fun x -> (new toto x :> _ basic) end;; class gentoto : object method gen : 'a -> 'a basic end 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