From: Martin Jambon <martin.jambon@ens-lyon.org>
To: Lukasz Stafiniak <lukstafi@gmail.com>
Cc: Zheng Li <li@pps.jussieu.fr>, caml-list@inria.fr
Subject: Re: [Caml-list] Re: records with polymorphic variants?
Date: Sun, 4 Mar 2007 13:02:57 -0800 (PST) [thread overview]
Message-ID: <Pine.LNX.4.64.0703041251000.2542@droopy> (raw)
In-Reply-To: <4a708d20703040824o20b1d572h786d46da586c9977@mail.gmail.com>
On Sun, 4 Mar 2007, Lukasz Stafiniak wrote:
> 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].
You can do this directly if you prefer:
type 'a f = 'a
constraint 'a = [> `A of int ]
>> 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.
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
--
Martin Jambon
http://martin.jambon.free.fr
next prev parent reply other threads:[~2007-03-04 21:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-04 6:03 Eliot Handelman
2007-03-04 12:04 ` [Caml-list] " Lukasz Stafiniak
2007-03-05 1:24 ` Jacques Garrigue
2007-03-04 12:08 ` Dmitri Boulytchev
2007-03-04 14:22 ` Zheng Li
2007-03-04 16:24 ` [Caml-list] " Lukasz Stafiniak
2007-03-04 16:50 ` Eliot Handelman
2007-03-04 21:02 ` Martin Jambon [this message]
2007-03-05 5:26 ` Eliot Handelman
2007-03-05 5:47 ` Martin Jambon
2007-03-05 8:01 ` Jacques GARRIGUE
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.0703041251000.2542@droopy \
--to=martin.jambon@ens-lyon.org \
--cc=caml-list@inria.fr \
--cc=li@pps.jussieu.fr \
--cc=lukstafi@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).