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 IAA13729; Tue, 4 Jun 2002 08:01:16 +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 IAA13725 for ; Tue, 4 Jun 2002 08:01:15 +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 g5461DL07784 for ; Tue, 4 Jun 2002 08:01:14 +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 IAA21045; Tue, 4 Jun 2002 08:57:21 +0900 (JST) To: la@iki.fi Cc: caml-list@inria.fr Subject: Re: [Caml-list] What about polymorphic methods? In-Reply-To: <20020602083443.GB2532@la.iki.fi> References: <3CEF08ED.80407@baretta.com> <20020525125530P.garrigue@kurims.kyoto-u.ac.jp> <20020602083443.GB2532@la.iki.fi> X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20020604085721U.garrigue@kurims.kyoto-u.ac.jp> Date: Tue, 04 Jun 2002 08:57:21 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Lauri Alanko > On Sat, May 25, 2002 at 12:55:30PM +0900, Jacques Garrigue wrote: > > With the CVS version, you would have to write > > > > method left_iter : 'b. ('a -> 'b) -> 'b list = fun f -> ... > > method right_iter : 'b. ('a -> 'b) -> 'b list = fun f -> ... > ^^^ > > Is this type parameter declaration really necessary? Since class type > parameters are explicitly declared already, can't method-specific type > parameters be recognized automatically? When writing a class type, you can omit them: class ['a] collection : object method left_iter : ('a -> 'b) -> 'b list method right_iter : ('a -> 'b) -> 'b list end This is ok because these method types are exact. However, in an implementation type annotations denote only constraints. That is, this 'b could actually be instanciated to something inside the class, or related to another type parameter by a constraint. The only way to say that it is going to be polymorphic at this level is to write it explicitly. Try: class c = object (self) method m1 : 'a -> 'a = fun x -> x method m2 = self#m1 1 end --------------------------------------------------------------------------- Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp JG ------------------- 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