Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Simple(?) subtyping problem...
[ 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] Simple(?) subtyping problem...
From: "Till Varoquaux" <>

> This would work but it isn't an option since I cannot get it to work
> with functors etc...
> AFAIK there's no way to specify a type must be a polymorphic variant
> without specfying any of it's members:
> if we are building a functor against:
> module type Evaluator=
> sig
>  ...
>  type 'a exp (*Is an exact polymorphic variant type *)
>  ...
> end
> we won't be able to write something like:
> type 'a t=[ `Some_label of 'a | 'a exp ]
> since the compiler won't be able to detect 'a exp was a polymorphic
> variant (note: it looks like there could also be an issue on the
> freshness of the new label)

There is indeed an issue of freshness :-)
There is code doing exactly what you ask for inside a branch in the
CVS for ocaml. The branch is still experimental, and is called
You would have to write
  type 'a exp = private [> ] ~ [`Some_label of 'a]
    (* `Some_label may only have type 'a (if present) *)
  type 'a exp = private [> ] ~ [`Some_label of 'a]
    (* `Some_label is absent *)
in order to be able to use it later in combination with `Some_label.

You can look at the code in testlabl/, which includes
examples corresponding exactly to the code you are trying to write.

Jacques Garrigue