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: | 2007-03-04 (16:24) |
From: | Lukasz Stafiniak <lukstafi@g...> |
Subject: | Re: [Caml-list] Re: records with polymorphic variants? |
On 3/4/07, Zheng Li <li@pps.jussieu.fr> wrote: > > Hi, > > Eliot Handelman <eliot@generation.net> writes: > > type f = [ `A of int ] > > > > type r = { x : f } > > > > but then I can't do this: > > > > { x = `B "test" } > Here you want type f polymorphic, however as the type of a record field, its > polymorphism has to be reflected (bound) as type parameter in the declaration > of r. Yes, but the type f itself is not polymorphic, it is not [> f]. > > I guess you want the follows > > # type 'a r = { x : 'a } constraint 'a = [> f] > type 'a r = { x : 'a; } constraint 'a = [> f ] > # {x = "test"} > Characters 6-12: > { x = "test"};; > ^^^^^^ > This expression has type string but is here used with type [> f ] > # {x = `B "test"} > - : [> `A of int | `B of string ] r = {x = `B "test"} > Nice! I didn't realize this is possible. Thanks.