Version française
Home     About     Download     Resources     Contact us    
Browse thread
records with polymorphic variants?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Zheng Li <li@p...>
Subject: Re: records with polymorphic variants?

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.

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"}

HTH, :)

--
Zheng Li
http://www.pps.jussieu.fr/~li/