From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 699F3BC6C for ; Thu, 3 May 2007 18:06:46 +0200 (CEST) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.225]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l43G6if7027647 for ; Thu, 3 May 2007 18:06:45 +0200 Received: by wr-out-0506.google.com with SMTP id l58so687224wrl for ; Thu, 03 May 2007 09:06:44 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=rcdXo3J7xnSQ+HWNGvh6ecgDyPjNgPhQN0omWZHnlUkzTE3UASRkdhjROEh6+KBb/bvo12/d+xb+5zSuGdbLMyXrw9E1fxZTsx95LjzarwW43rsu3EFVSNv0yH2Ti8tp6K7KPCs5hTw0tGYLY+N+Sn9JbCqtDCO5qzmW6y4Te9o= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=gIwU+NkRFRRdkGwDUdSJwqNAgrss3T1R4RA26mo7eRes01NgFFQ2vfudgYFENmm9/nglDBI5CAfvGC57sRv9fJzVaF+EYLUeRGH5md+YF5D2DzhA3HIcNmxEL/QVnV00b8acG6xCHezcezx2Wz6VJbTZYGkJHLVyLVNJCWcTSsQ= Received: by 10.114.121.1 with SMTP id t1mr748659wac.1178208404024; Thu, 03 May 2007 09:06:44 -0700 (PDT) Received: by 10.114.183.15 with HTTP; Thu, 3 May 2007 09:06:43 -0700 (PDT) Message-ID: Date: Thu, 3 May 2007 18:06:43 +0200 From: "Nicolas Pouillard" To: "Till Varoquaux" Subject: Re: Abstract types in the revised syntax Cc: "Caml List" , "=?UTF-8?Q?G=C3=A9rard_Huet?=" , "Benoit Razet" In-Reply-To: <9d3ec8300705030848h7395c26eq5fd6bd2e8942762b@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <9d3ec8300705030848h7395c26eq5fd6bd2e8942762b@mail.gmail.com> X-j-chkmail-Score: MSGID : 463A0894.003 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 463A0894.003 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; syntax:01 camlp:01 ctyp:01 ctyp:01 cheers:01 syntax:01 existential:01 existential:01 parser:01 syntaxes:01 bug:01 parser:01 ocaml:01 sig:01 sig:01 On 5/3/07, Till Varoquaux wrote: > I happen to very much dislike dangling free variables and therefore > think this would be a nice improvement. > Thanks for fixing my constraint issues. > BTW I still haven't figured out how to generate constraints (lets say > I have a list of strings [t1,..,tn] and a list of idents [c1...cn], > how do I generate the type < c1:t1; ... ; cn:tn >? ) That way... open Camlp4.PreCast;; let mk_obj_type _loc fields types = let object_type = List.fold_right2 begin fun field typ object_type -> <:ctyp< $lid:field$ : $lid:typ$ ; $object_type$ >> end fields types <:ctyp<>> in <:ctyp< < $object_type$ > >> ;; mk_obj_type (Loc.mk "") ["f1"; "f2"] ["t1"; "t2"];; > > Cheers, > Till > > On 5/3/07, Nicolas Pouillard wrote: > > Hello, > > > > This message concern the few people that use the revised syntax :) > > > > In the revised syntax, abstract types are expressed by defining them > > with an unbound type variable: > > > > (* Original *) > > type t;; > > > > (* Revised *) > > type t = 'a; > > > > The motivation is that looks like an existential type, which is a way > > of seeing abstract types. > > > > However I found this motivation misapplied since it doesn't look like > > an existential type, there is no exists keyword?!? (type t = exists > > 'a. 'a;) > > > > It's like a hot-dog without sausage?!? > > > > In fact, consequences of that choice are worst. If forces the > > parser/printer to do some semantical operation to convert back and > > forth between syntaxes. > > > > type t 'a = 'a; (* not abstract *) > > > > type t 'a = 'b; (* abstract *) > > > > It was considered acceptable, since the test for the freeness of a > > single type variable seemed simple because very local. > > > > Indeed only the list of parameters was consulted to compute the > > freeness of the type variable. > > > > It seems very weak since highly dependent of future evolution of the language. > > > > Nowadays it's no longer sufficient. Constraints can be added with a > > type declaration to constrain the type of parameters. > > > > type c 'a = 'b > > constraint 'a = < b : 'b; .. >; > > (* Thanks to Till Varoquaux for it's bug report. *) > > > > Clearly I don't want to push that wrong choice further by making more > > semantic analysis in the parser/printer. > > > > So I revert back to << type t; >> for abstract types. > > > > Now, what's the new representation for abstract types. OCaml use a > > option type, where None represent the abstract type. We can't afford > > that, since we want a concrete syntax for everything. > > However we have a nil type that can be used as a default case (for > > lists of types or optional types). > > > > <:sig_item< type t >> === <:sig_item< type t = $ <:ctyp<>> $ >> > > > > Not that this will also concern abstract module types. > > > > Alas, this will affect existing code using the revised syntax, but > > will be easily caught at compilation. > > > > From a pragmatic point of view, a grep to show the usage of such types: > > grep -E "^[ \t]*type.*=[ \t]*'[^ \t]*[ \t]*;[ \t]*$" **/*.ml* > > > > Feel free to share your mind on that subject. The change is not yet > > applied to the CVS. > > > > Best regards, > > > > -- > > Nicolas Pouillard > > > -- Nicolas Pouillard