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 OAA08080; Tue, 25 Mar 2003 14:07:12 +0100 (MET) 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 OAA08350 for ; Tue, 25 Mar 2003 14:07:11 +0100 (MET) Received: from mail0.epfl.ch (mail0.epfl.ch [128.178.50.57]) by nez-perce.inria.fr (8.11.1/8.11.1) with SMTP id h2PD7AX05622 for ; Tue, 25 Mar 2003 14:07:10 +0100 (MET) Received: (qmail 25814 invoked from network); 25 Mar 2003 13:07:10 -0000 Received: from lamppc32.epfl.ch (HELO epfl.ch) (128.178.154.41) by mail0.epfl.ch with SMTP; 25 Mar 2003 13:07:10 -0000 Message-ID: <3E80547E.2010201@epfl.ch> Date: Tue, 25 Mar 2003 14:07:10 +0100 From: Sebastien Briais User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en, fr-fr MIME-Version: 1.0 To: Jacques Garrigue CC: caml-list@inria.fr Subject: Re: [Caml-list] About polymorphic methods and recursive classes References: <3E7C4784.6000901@epfl.ch> <20030324094415.6679de19.Damien.Pous@ens-lyon.fr> <3E7F457A.80006@epfl.ch> <20030325101545S.garrigue@kurims.kyoto-u.ac.jp> In-Reply-To: <20030325101545S.garrigue@kurims.kyoto-u.ac.jp> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Spam: no; 0.00; caml-list:01 jacques:01 inferred:01 generic:01 ocaml:01 inherit:01 int:01 garrigue:01 polymorphic:01 typing:03 classes:03 interpreter:03 wrote:03 recursive:03 nil:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Jacques Garrigue wrote: >From: Sebastien Briais > > >>>># class virtual ['a] visitor = >>>> object >>>> method virtual caseNil : 'a >>>> end >>>> and virtual int_list = >>>> object >>>> method virtual visit : 'a.('a visitor -> 'a) >>>> end >>>> ;; >>>>class virtual ['a] visitor : object method virtual caseNil : 'a end >>>>class virtual int_list : object method virtual visit : 'a visitor -> >>>>'a end >>>> >>>> >>I am still puzzled by the answer of the interpreter which says me that >>"v has type 'a visitor; It has no method caseNil" >>although it has inferred just before that >>"class virtual ['a] visitor : object method virtual caseNil : 'a end" >> >>Moreover, it seems odd to me that it works with class types but not without. >>These class types should be inferred by Ocaml, shouldn't they ? (and >>they seems >>to be correctly inferred in my example (in the first part of it)) >> >> > >Actually no. Polymorphic methods are not inferred, but declared. >And polymorphic type variables should not be used as parameters to >simultaneously defined types. >Actually, your mutually recursive definition should not be accepted to >begin with. It clearly results in a wrong internal type. > > So, if I understand you well, it is not possible to write something like that in ocaml: class virtual ['a,'b] list_visitor = object method virtual caseNil : 'a method virtual caseCons : 'b -> 'b list -> 'a end and virtual ['b] list = object method virtual visit : 'a.(('a,'b) list_visitor -> 'a) end class ['a] nil = object inherit ['a] list method visit v = v#caseNil end class ['a] cons = fun h t -> object inherit ['a] list method visit v = v#caseCons h t end and especially, the first definition should be considered as incorrect since the polymorphic variable 'a of list is used as a parameter of the list_visitor. But what is the reason of this limitation ? I do not see the reasons since for example, in Generic Java, such a definition is correct abstract class Visitor { abstract a caseNil(); abstract a caseCons(b x, List xs); } abstract class List { abstract a visit(Visitor v); } Can you explain in more details your answer ? Does it lead to type insafety or indecidability of typing to authorize polymorphic type variables to be used as parameters to simulteanously defined types ? Regards Sébastien ------------------- 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