caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* conjunctive type in polymorphic variants
@ 2008-10-09  4:15 Conglun Yao
  2008-10-09  7:22 ` [Caml-list] " Nicolas Pouillard
  2008-10-09  8:43 ` Olivier Andrieu
  0 siblings, 2 replies; 4+ messages in thread
From: Conglun Yao @ 2008-10-09  4:15 UTC (permalink / raw)
  To: caml-list

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

It looks wired, as we can directly define
type t = [ `A of int * int | `B of string ]  in toploop or a *.ml file.

Or I have some mis-understanding in this part.

Thanks for any help.

Best regards,
Conglun


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-10-09 10:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-09  4:15 conjunctive type in polymorphic variants Conglun Yao
2008-10-09  7:22 ` [Caml-list] " Nicolas Pouillard
2008-10-09  8:43 ` Olivier Andrieu
2008-10-09 10:09   ` Conglun Yao

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).