Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Nicolas Pouillard <nicolas.pouillard@g...>
Subject: Re: [Caml-list] conjunctive type in polymorphic variants
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