From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 4E2A0BB81 for ; Tue, 14 Feb 2006 01:03:00 +0100 (CET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k1E02vqY010872 for ; Tue, 14 Feb 2006 01:02:59 +0100 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id k1E02hgI013100; Tue, 14 Feb 2006 09:02:44 +0900 (JST) Date: Tue, 14 Feb 2006 09:04:23 +0900 (JST) Message-Id: <20060214.090423.92585678.garrigue@math.nagoya-u.ac.jp> To: basile@starynkevitch.net Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] (quasi FAQ) object, variants, .... Unbound type parameter [..] From: Jacques Garrigue In-Reply-To: <20060213192936.GA6605@ours.starynkevitch.net> References: <20060213192936.GA6605@ours.starynkevitch.net> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 43F11E31.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 variants:01 basile:01 basile:01 node:01 recursive:01 node:01 intending:01 sig:01 struct:01 ess:98 unbound:01 unbound:01 faq:01 int:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=DNS_FROM_RFC_ABUSE autolearn=disabled version=3.0.3 From: Basile STARYNKEVITCH > class virtual ['VarT,'NodeT] myclass = object(self) > method virtual v : 'VarT > method virtual n : 'NodeT > end;; > > type > 'a vart = [> `NothingV | `IntegerV of int | `NodeV of 'a nodet ] > and > 'a nodet = Empty | LeafI of int | ObLeaf of 'a instancet | Node of nodet list > and > 'a instancet = ('a,nodet) myclass constraint 'a = 'a vart > > > I'm getting the following error > > File "ess.ml", line 8, characters 12-66: > Unbound type parameter [..] There are two problems here. One is that your definition of vart is invalid: the ">" introduce a type variable that is bound nowhere (this is the direct cause of the error.) Even if you correct this, another problem is that, in mutually recursive definitions, constraints must be repeated everywhere they are needed. So a straightforward correction would be: type 'a vart = [ `NothingV | `IntegerV of int | `NodeV of 'a ] type 'a nodet = Empty | LeafI of int | ObLeaf of 'a instancet | Node of 'a nodet list constraint 'a = [> 'a nodet vart] and 'a instancet = ('a,'a nodet) myclass constraint 'a = [> 'a nodet vart] Now, I don't know what kind of code you are intending to write, but depending of the kind of parameterization you are using, a functorized version could be more natural: type 'a vart = [ `NothingV | `IntegerV of int | `NodeV of 'a ] module F(X : sig type 'a t = private [> 'a vart] end) = struct type nodet = Empty | LeafI of int | ObLeaf of 'a instancet | Node of 'a nodet list and instancet = ... end The nice part is that individual constraints disappear: they are fully expressed by the signature of X. Jacques Garrigue