From: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
To: Conglun Yao <yaoconglun@gmail.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] conjunctive type in polymorphic variants
Date: Thu, 09 Oct 2008 09:22:58 +0200 [thread overview]
Message-ID: <1223536837-sup-6068@ausone.inria.fr> (raw)
In-Reply-To: <f7b50d2a0810082115v6a604241l598c828611614c77@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1349 bytes --]
Excerpts from Conglun Yao's message of Thu Oct 09 06:15:16 +0200 2008:
> Hi all,
>
> I have just met a strange problem (it might have already been
> answered, but I can't find the it) while using camlp4 to generate a
> polymorphic type like:
>
> type t = [ `A of int * int | `B of string ]
>
> error msg "The present constructor A has a conjunctive type" is thrown
> by the compiler.
>
> I followed the ocaml source code, found in ocaml-3.10.2/typing/typetexp.ml
> Line 290, it does the following check in add_field function:
> if List.length stl > 1 || c && stl <> [] then
> raise(Error(styp.ptyp_loc, Present_has_conjunction l));
>
> Sorry, I can't fully understand the source code, but it seems we can
> only define a polymorphic variant with only one additional type
> declaration, like
> `A of int or `A of (int * int)
> rather than `A of int * int
Right.
> It looks wired, as we can directly define
> type t = [ `A of int * int | `B of string ] in toploop or a *.ml file.
I think there is some syntactic thing to make it equal to `A of (int * int) in
this case since `A of int * int does not make sense.
> Or I have some mis-understanding in this part.
In your camlp4 code you have to add tuple nodes to wrap star nodes:
<:ctyp< $tup:t$ >>
Best regards,
--
Nicolas Pouillard aka Ertai
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 240 bytes --]
next prev parent reply other threads:[~2008-10-09 7:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-09 4:15 Conglun Yao
2008-10-09 7:22 ` Nicolas Pouillard [this message]
2008-10-09 8:43 ` [Caml-list] " Olivier Andrieu
2008-10-09 10:09 ` Conglun Yao
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=1223536837-sup-6068@ausone.inria.fr \
--to=nicolas.pouillard@gmail.com \
--cc=caml-list@inria.fr \
--cc=yaoconglun@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