<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2006/02/13a2523f313929ab46731a5fb41a7742"
  from="Jacques Garrigue &lt;garrigue@m...&gt;"
  author="Jacques Garrigue"
  date="2006-02-14T00:03:00"
  subject="Re: [Caml-list] (quasi FAQ) object, variants, .... Unbound type parameter [..]"
  prev="2006/02/ee7c18da8116e31dd45fc11796083127"
  next="2006/02/e2ac6157fdcc6fcaefdce3f8dd56911d"
  prev-in-thread="2006/02/ee7c18da8116e31dd45fc11796083127"
  prev-thread="2006/02/90d9e4642462c7664427ec1e4375a828"
  next-thread="2006/02/e2ac6157fdcc6fcaefdce3f8dd56911d"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="(quasi FAQ) object, variants, .... Unbound type parameter [..]">
<msg 
  url="2006/02/4c3947fbf7a2d35c0dee767bba62dfa0"
  from="Basile STARYNKEVITCH &lt;basile@s...&gt;"
  author="Basile STARYNKEVITCH"
  date="2006-02-13T19:29:37"
  subject="(quasi FAQ) object, variants, .... Unbound type parameter [..]">
<msg 
  url="2006/02/ee7c18da8116e31dd45fc11796083127"
  from="Martin Jambon &lt;martin_jambon@e...&gt;"
  author="Martin Jambon"
  date="2006-02-13T20:43:37"
  subject="Re: [Caml-list] (quasi FAQ) object, variants, .... Unbound type parameter [..]">
</msg>
<msg 
  url="2006/02/13a2523f313929ab46731a5fb41a7742"
  from="Jacques Garrigue &lt;garrigue@m...&gt;"
  author="Jacques Garrigue"
  date="2006-02-14T00:03:00"
  subject="Re: [Caml-list] (quasi FAQ) object, variants, .... Unbound type parameter [..]">
</msg>
</msg>
</thread>

<contents>
From: Basile STARYNKEVITCH &lt;basile@starynkevitch.net&gt;
&gt;   class virtual ['VarT,'NodeT] myclass = object(self)
&gt;     method virtual v : 'VarT
&gt;     method virtual n : 'NodeT
&gt;   end;;
&gt; 
&gt;   type 
&gt;     'a vart = [&gt; `NothingV | `IntegerV of int | `NodeV of 'a nodet ]
&gt;   and
&gt;     'a nodet = Empty | LeafI of int | ObLeaf of 'a instancet | Node of nodet list
&gt;   and
&gt;     'a instancet = ('a,nodet) myclass constraint 'a = 'a vart
&gt; 
&gt; 
&gt; I'm getting the following error
&gt; 
&gt; File "ess.ml", line 8, characters 12-66:
&gt; Unbound type parameter [..]

There are two problems here. One is that your definition of vart is
invalid: the "&gt;" 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 = [&gt; 'a nodet vart]
and 'a instancet = ('a,'a nodet) myclass constraint 'a = [&gt; '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 [&gt; 'a vart] end) = struct
  type nodet =
    Empty | LeafI of int | ObLeaf of 'a instancet | Node of 'a nodet list
  and instancet = &lt;v : nodet X.t; n : nodet&gt;
  ...
end

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

Jacques Garrigue

</contents>

</message>

