Version française
Home     About     Download     Resources     Contact us    
Browse thread
(quasi FAQ) object, variants, .... Unbound type parameter [..]
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] (quasi FAQ) object, variants, .... Unbound type parameter [..]
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