From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by yquem.inria.fr (Postfix, from userid 25991) id 2F728BBAF; Mon, 6 Dec 2010 10:11:00 +0100 (CET) Date: Mon, 6 Dec 2010 10:11:00 +0100 From: Daniel de Rauglaudre To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] GADT constructor syntax Message-ID: <20101206091100.GA21369@yquem.inria.fr> References: <1245532236.1431213.1291490707868.JavaMail.root@zmbs3.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1245532236.1431213.1291490707868.JavaMail.root@zmbs3.inria.fr> User-Agent: Mutt/1.5.9i X-Spam: no; 0.00; rauglaudre:01 rauglaudre:01 syntax:01 0100,:01 bool:01 bool:01 camlp:01 syntax:01 constructors:01 constructors:01 curried:01 ocaml:01 compiler:01 camlp:01 ocaml:01 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/