Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
conjunctive type in polymorphic variants
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-10-09 (04:15)
From: Conglun Yao <yaoconglun@g...>
Subject: conjunctive type in polymorphic variants
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/
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,