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 LAA10292; Sat, 8 Jun 2002 11:46:59 +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 LAA10268 for ; Sat, 8 Jun 2002 11:46:58 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from athlon.baretta.com (r-mi214-6a141.tin.it [62.211.4.141]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g589kvH02927 for ; Sat, 8 Jun 2002 11:46:57 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id 5BF97273E4 for ; Sat, 8 Jun 2002 11:52:19 +0200 (CEST) Message-ID: <3D01D3D3.701@baretta.com> Date: Sat, 08 Jun 2002 11:52:19 +0200 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0rc1) Gecko/20020417 X-Accept-Language: it, en MIME-Version: 1.0 To: Ocaml Subject: Re: [Caml-list] What about polymorphic methods References: <3CEF08ED.80407@baretta.com> <20020525125530P.garrigue@kurims.kyoto-u.ac.jp> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Jacques Garrigue wrote: > > Indeed, iterators are one of the major reasons to have polymorphic > methods in ocaml (the other one being implicit subtyping of > arguments). They are already in CVS, and will be present in ocaml > 3.05. > > 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 -> ... Hello Jacques and Caml riders, I am very excited about the possibilities offered by the polymorphic methods of Ocaml 3.04+13, which I have recently downloaded and built from the CVS site. Please, allow me one more question on this matter. I do not understand why I have to declare 'b explicitly as a "polymorphic" type variable for the two iterators. If I omit the explicit generalization of 'b in my bidirectional list class, the compiler yields the following error message: > Some type variables are unbound in this type: > class ['a] bidi_list : > 'a list -> > object > val first : 'a bidi > val last : 'a bidi > method head : 'a bidi > method left_iter : ('a -> 'b) -> 'b list > method right_iter : ('a -> 'c) -> 'c list > method tail : 'a bidi > end > The method left_iter has type ('a -> 'b) -> 'b list where > 'b is unbound An analogous error message would be given for right_iter, with reference to 'c, if the explicit generalization were used for left_iter. To me, this means that the type checker is able to correctly determine the type of the class and of the polymorphic methods. It simply refuses to generalize unbound type variables without "written consent" from the programmer. I think that coding a method whose type contains an unbound type variable, implicitly means that the programmer desires that type variable to be generalized. Since the compiler is able to determine what type variables "ought" to be generalized, why does it not perform and "implicit" generalization, rather than requiring an "explicit" generalization in the code? I hope I am making some sense to somebody. Do excuse me if I have used improper terminology, but I am not a professional of functional languages and type theory. Regards, Alex Baretta ------------------- 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