Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] GADT constructor syntax
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Daniel de Rauglaudre <daniel.de_rauglaudre@i...>
Subject: Re: [Caml-list] GADT constructor syntax
Hi,

On Sat, Dec 04, 2010 at 08:25:07PM +0100, Jacques Le Normand wrote:

> option a)
> type _ t =
>         TrueLit : bool t
>       | IntLit of int : int lit
> option b)
> type _ t =
>       TrueLit : bool t
>     | IntLit : int -> int lit

For a:
  A little bit easier to parse (as a Camlp5 designer), which is just
  a parse of the 'of' part followed (or not) with the ':' and another
  type. In the option b), in the "revised" syntax version, I decided
  to also separate the constructor parameters with arrows, which forced
  me to add a function separating the ending type, the parsing being
  therefore more complicated.

For b:
  1/ The difference between normal constructors and constructors with GADT
     is very visible. All examples given here are often with definitions
     which are relatively short, but I tried an example with constructors
     with several long types and I like the idea of seing immediately
     that they are GADTs, rather at the end of the definition line (or
     lines).
  2/ I like the idea of defininig them with a syntax like the one of
     functions definitions, like 'val'. In the "revised" syntax version,
     where the constructors parameters are in "curried" form, this is
     even more readable (even if partially applied parameters are
     not accepted in the OCaml compiler).

PS The latest version of Camlp5 works with Jacques' version. You can
download it at: http://pauillac.inria.fr/~ddr/camlp5/

PPS The version with GADT is very interesting to parse parsing rules. I
is what I was searching for many years. In Camlp[45], the EXTEND statement
generates calls to Obj.magic and types constraints to "extend" the
OCaml type system. (This cannot be simulated by first class modules.)

-- 
Daniel de Rauglaudre
http://pauillac.inria.fr/~ddr/