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: Olivier Andrieu <oandrieu@n...>
Subject: Re: [Caml-list] conjunctive type in polymorphic variants
Hi,

On Thu, Oct 9, 2008 at 06:15, Conglun Yao <yaoconglun@gmail.com> wrote:
> 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

That's correct.

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

yes, that's because ocaml handle the "of int * int" a bit differently
in regular and
polymorphic variant declarations:
  - in the regular variant the * is a separator between constructor
arguments (thus two arguments)
  - polymorphic variants only have one argument, so int * int is
treated as a whole type expression and * is the "tupling" operator

So yes, this looks wired in the ocaml parser.

-- 
  Olivier