Browse thread
records with polymorphic variants?
[
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: | Lukasz Stafiniak <lukstafi@g...> |
| Subject: | Re: [Caml-list] records with polymorphic variants? |
This question should go to the "OCaml Beginners"
<ocaml_beginners@yahoogroups.com>.
On 3/4/07, Eliot Handelman <eliot@generation.net> wrote:
> Hi,
>
> I'm trying to figure out how to define a record with a field whose type
> is an extensible polymorphic variant.
>
> I can this:
>
> type f = [ `A of int ]
>
> type r = { x : f }
>
> but then I can't do this:
>
> { x = `B "test" }
This is crearly a type mismatch: you specified r.x to allow only `A of int.
>
> I'm not even sure if what I'm asking for is possible.
>
I don't think so.
> Guessing at the syntax I tried
>
> type r = {
> f : [> #foo]
> }
>
> which results in:
>
> Warning D: this syntax is deprecated.
> f : [> #foo]
> ^^^^
> Characters 24-28:
> f : [> #foo]
> ^^^^
> The type [< foo ] is not a polymorphic variant type
>
Try the syntax:
# type r = {x : [> foo]};;
Characters 14-21:
type r = {x : [> foo]};;
^^^^^^^
Unbound type parameter [..]
The open variant type introduces a type parameter, which is not bound
in definition of type r. I don't think these unnamed parameters can be
bound, so that you could write:
"type 'a r = {x : foo SUM 'a}".
> I hope it is clear what I'm trying to do. Thanks for your help.
>
No, it is not clear. You haven't specified the context.