caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* (quasi FAQ) object, variants, .... Unbound type parameter [..]
@ 2006-02-13 19:29 Basile STARYNKEVITCH
  2006-02-13 20:43 ` [Caml-list] " Martin Jambon
  2006-02-14  0:04 ` Jacques Garrigue
  0 siblings, 2 replies; 3+ messages in thread
From: Basile STARYNKEVITCH @ 2006-02-13 19:29 UTC (permalink / raw)
  To: caml-list


Hello All,

I'm a bit ashamed to ask such a quasi FAQ, but I don't understand why
the following does not compile


  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 [..]

which is positionned inside the bracket [] of vart line.

Sorry for asking such a nearly FAQ; I thought that this would be a
nearly canical example of the use of constraint.

The real context of all this is some scriptable Wiki-like application
which contains a (dynamically typed) interpreter (quasi scheme
semantics with some ml-like or ada-like syntax). The actual need is to
box in an open variant type (like vart above) all the "special" values
of the interpreter.


Again, my apologies for asking a nearly FAQ... (I googled a bit, but
did not understood the relation between the answers & my question).

Regards

-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/ 
email: basile<at>starynkevitch<dot>net 
aliases: basile<at>tunes<dot>org = bstarynk<at>nerim<dot>net
8, rue de la Faïencerie, 92340 Bourg La Reine, France


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] (quasi FAQ) object, variants, .... Unbound type parameter [..]
  2006-02-13 19:29 (quasi FAQ) object, variants, .... Unbound type parameter [..] Basile STARYNKEVITCH
@ 2006-02-13 20:43 ` Martin Jambon
  2006-02-14  0:04 ` Jacques Garrigue
  1 sibling, 0 replies; 3+ messages in thread
From: Martin Jambon @ 2006-02-13 20:43 UTC (permalink / raw)
  To: Basile STARYNKEVITCH; +Cc: caml-list

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2559 bytes --]

On Mon, 13 Feb 2006, Basile STARYNKEVITCH wrote:

>
> Hello All,
>
> I'm a bit ashamed to ask such a quasi FAQ, but I don't understand why
> the following does not compile
>
>
>  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

Maybe something like that:

class virtual ['VarT,'NodeT] myclass = object(self)
   method virtual v : 'VarT
   method virtual n : 'NodeT
end;;

(* 'a = 'VarT
    'b = 'NodeT *)
type ('a, 'b) nodet_poly =
     Empty
   | LeafI of int
   | ObLeaf of ('a, 'b) instancet_poly
   | Node of ('a, 'b) nodet_poly
and
   ('a, 'b) instancet_poly = ('b, ('a, 'b) nodet_poly) myclass

(* 'b = 'NodeT is constrained in vart *)
type ('a, 'b) vart = 'b
constraint 'b =
     [> `NothingV | `IntegerV of int | `NodeV of ('a, 'b) nodet_poly ]

type ('a, 'b) instancet = (('a, 'b) vart, ('a, 'b) nodet_poly) myclass


Martin

> I'm getting the following error
>
> File "ess.ml", line 8, characters 12-66:
> Unbound type parameter [..]
>
> which is positionned inside the bracket [] of vart line.
>
> Sorry for asking such a nearly FAQ; I thought that this would be a
> nearly canical example of the use of constraint.
>
> The real context of all this is some scriptable Wiki-like application
> which contains a (dynamically typed) interpreter (quasi scheme
> semantics with some ml-like or ada-like syntax). The actual need is to
> box in an open variant type (like vart above) all the "special" values
> of the interpreter.
>
>
> Again, my apologies for asking a nearly FAQ... (I googled a bit, but
> did not understood the relation between the answers & my question).
>
> Regards
>
> -- 
> Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
> email: basile<at>starynkevitch<dot>net
> aliases: basile<at>tunes<dot>org = bstarynk<at>nerim<dot>net
> 8, rue de la Faïencerie, 92340 Bourg La Reine, France
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

--
Martin Jambon, PhD
http://martin.jambon.free.fr

Visit http://wikiomics.org, the Bioinformatics Howto Wiki

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] (quasi FAQ) object, variants, .... Unbound type parameter [..]
  2006-02-13 19:29 (quasi FAQ) object, variants, .... Unbound type parameter [..] Basile STARYNKEVITCH
  2006-02-13 20:43 ` [Caml-list] " Martin Jambon
@ 2006-02-14  0:04 ` Jacques Garrigue
  1 sibling, 0 replies; 3+ messages in thread
From: Jacques Garrigue @ 2006-02-14  0:04 UTC (permalink / raw)
  To: basile; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-02-14  0:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-13 19:29 (quasi FAQ) object, variants, .... Unbound type parameter [..] Basile STARYNKEVITCH
2006-02-13 20:43 ` [Caml-list] " Martin Jambon
2006-02-14  0:04 ` Jacques Garrigue

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).