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 EAA27843; Mon, 8 Jul 2002 04:53:12 +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 EAA27738 for ; Mon, 8 Jul 2002 04:53:11 +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 g682r7903930 for ; Mon, 8 Jul 2002 04:53:09 +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 LAA07809; Mon, 8 Jul 2002 11:53:01 +0900 (JST) To: brian-l-smith@uiowa.edu Cc: caml-list@inria.fr Subject: Re: [Caml-list] Polymorphic methods (longest error message ever!) In-Reply-To: <3D28E9F8.5020308@uiowa.edu> References: <3D28E9F8.5020308@uiowa.edu> 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: <20020708115301R.garrigue@kurims.kyoto-u.ac.jp> Date: Mon, 08 Jul 2002 11:53:01 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Brian Smith > First of all, where can I find some documentation about the CVS versino > of O'Caml? Is the documentation kept in CVS too? Yes, but it is not public. Anyway, it is not updated simultaneously with the source, so you wont't find the documentation for a new feature there immediately. So basically, new features in CVS are given as is, without other documentation than asking the developpers. In the present case, the release is probably not too far away, so you should not have to wait too long. Until that, for polymorphic methods, there are examples in testlabl/poly.ml, but it's about all. > Anyway, on to the problem at hand: > That works fine in O'Caml 3.04. But, I want to use the new polymorphic > method feature in O'Caml 3.04+15. So I tried: > > # class type node_type = object > method as_variant : [> `Node of node_type] > end;; > class type node_type = > object method as_variant : [> `Node of node_type] end > > # class node : node_type = object (self) > method as_variant = `Node (self :> node_type) > end;; > ^^^^ > This expression cannot be coerced to type > node_type = < as_variant : 'a. [> `Node of node_type] as 'a >; > it has type < as_variant : 'c; .. > as 'b but is here used with type 'b That one is correct behaviour: as_variant is inferred to be monomorphic, since in the first pass the checker doesn't look inside method, where is your only type annotation. (Unfortunately the node: node_type constraint is only applied afterwards, applying it early being rather complex.) > # class node : node_type = object (self) > method as_variant : 'a. [> `Node of node_type] as 'a > = `Node (self :> node_type) > end;; > The class type object method as_variant : [> `Node of node_type] end > is not matched by the class type node_type > The class type object method as_variant : [> `Node of node_type] end > is not matched by the class type > object method as_variant : [> `Node of node_type] end > The method as_variant has type 'a. [> `Node of node_type] as 'a > but is expected to have type 'b. [> `Node of node_type] as 'b > The universal variable 'b would escape its scope > > I have no idea what the error message means. To me, it is saying that > class "node" doesn't match class type "node_type" even though everything > has exactly the same type. Could somebody please explain it to me? What > is the correct way of doing the above? As skaller says, this is hardly a long message :-) It is also clearly wrong: it tells you that two identical types are incompatible. The problem seems to come from the node : node_type part. The following version works: # class node = object (self) method as_variant : 'a. [> `Node of node_type] as 'a = `Node (self :> node_type) end;; class node : object method as_variant : [> `Node of node_type] end And that shorter one also: # class node = object (self : #node_type) method as_variant = `Node (self :> node_type) end;; class node : object method as_variant : [> `Node of node_type] end Thank you for the bug report, I'll try to correct it. Jacques ------------------- 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