Browse thread
Simple(?) subtyping problem...
-
Till Varoquaux
- Jon Harrop
-
Jacques Garrigue
-
Till Varoquaux
- Jacques Garrigue
-
Till Varoquaux
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ 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" <till.varoquaux@gmail.com>
> 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
varunion.
You would have to write
type 'a exp = private [> ] ~ [`Some_label of 'a]
(* `Some_label may only have type 'a (if present) *)
or
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/varunion.ml, which includes
examples corresponding exactly to the code you are trying to write.
Jacques Garrigue