caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <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 [..]
Date: Tue, 14 Feb 2006 09:04:23 +0900 (JST)	[thread overview]
Message-ID: <20060214.090423.92585678.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <20060213192936.GA6605@ours.starynkevitch.net>

From: Basile STARYNKEVITCH <basile@starynkevitch.net>
>   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 = <v : nodet X.t; n : nodet>
  ...
end

The nice part is that individual constraints disappear: they are fully
expressed by the signature of X.

Jacques Garrigue


      parent reply	other threads:[~2006-02-14  0:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-13 19:29 Basile STARYNKEVITCH
2006-02-13 20:43 ` [Caml-list] " Martin Jambon
2006-02-14  0:04 ` Jacques Garrigue [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060214.090423.92585678.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=basile@starynkevitch.net \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).