Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "Lukasz Stafiniak" <lukstafi@gmail.com>
To: eliot@generation.net
Cc: caml <caml-list@inria.fr>
Subject: Re: [Caml-list] records with polymorphic variants?
Date: Sun, 4 Mar 2007 13:04:22 +0100	[thread overview]
Message-ID: <4a708d20703040404y4973ca00if881bd4ef65f3a1e@mail.gmail.com> (raw)
In-Reply-To: <45EA613F.3030104@generation.net>

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.


  reply	other threads:[~2007-03-04 12:04 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 ` Lukasz Stafiniak [this message]
2007-03-05  1:24   ` [Caml-list] " 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
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=4a708d20703040404y4973ca00if881bd4ef65f3a1e@mail.gmail.com \
    --to=lukstafi@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=eliot@generation.net \
    /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