Browse thread
conjunctive type in polymorphic variants
-
Conglun Yao
- Nicolas Pouillard
-
Olivier Andrieu
- Conglun Yao
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2008-10-09 (10:09) |
From: | Conglun Yao <yaoconglun@g...> |
Subject: | Re: [Caml-list] conjunctive type in polymorphic variants |
Nicolas and Olivier, Thanks for your quick reply, it makes sense! Conglun On Thu, Oct 9, 2008 at 9:43 AM, Olivier Andrieu <oandrieu@nerim.net> wrote: > 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 >