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.2 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id B114CBC69 for ; Sun, 25 Mar 2007 22:47:03 +0200 (CEST) Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.232]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2PKl267031437 for ; Sun, 25 Mar 2007 22:47:03 +0200 Received: by nz-out-0506.google.com with SMTP id l8so1347900nzf for ; Sun, 25 Mar 2007 13:47:01 -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:mime-version:content-type:content-transfer-encoding:content-disposition; b=GmTQbnYVD2bx3N7l8IBw6QO7YBkWbS02RvEdLjgc5Uy8SeMc4V6kzrMZcY7OHBfeh4ouo0rf0eTbBHGBCt6Oli1F+KRaoAAj4GiLews/Y2cMt+zmK9MHdR6DS4jKX3J9g3yrIZTylmvyueSzdLZTXufjSWcGooJI9ZFrGnL78/M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:mime-version:content-type:content-transfer-encoding:content-disposition; b=a/3CtDQdGTunzR5kt8VZj+0r+kUqmpybVYwihT0RuGbPq0Uu2H3mCLPBKcADRVwsECFwaZykQcV/smZTO7S9ctMEs1u+3bunJqY9+Pzac9CYrHbe3yUR9xccRQneJRP/4bWAu0/FH6b8Ihz8yRXspDY2epsCX42ZBPoTfRb9v5s= Received: by 10.114.195.19 with SMTP id s19mr2334134waf.1174855620976; Sun, 25 Mar 2007 13:47:00 -0700 (PDT) Received: by 10.114.183.4 with HTTP; Sun, 25 Mar 2007 13:47:00 -0700 (PDT) Message-ID: Date: Sun, 25 Mar 2007 22:47:00 +0200 From: "Nicolas Pouillard" To: "Martin Jambon" Subject: [Camlp4 3.10] The rosetta stone (Was: lists without $list:...$) Cc: caml-list@inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-j-chkmail-Score: MSGID : 4606DFC6.000 on concorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at concorde with ID 4606DFC6.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlp:01 ens-lyon:01 syntax:01 sexp:01 syntax:01 ioxml:01 translated:01 camlp:01 ctyp:01 ml':01 ctyp:01 constructors:01 meth:01 cheers:01 stone:98 On 3/24/07, Martin Jambon wrote: > > I would like you or anyone knowledgeable to translate one significant > syntax extension. You know, some kind of Rosetta stone. You can take > Markus' sexp syntax extension or ioxml if you prefer, it won't be much > different. Here is your rosetta stone :) I translated pa_json_static.ml. To highlight a little the changes in the AST, I want to show an input snippet and two translations: For the old camlp4 it was: | Object l -> let ml = List.map (fun x -> (x.field_caml_name, convert x.field_type)) l in <:ctyp< < $list:ml$ > >> The type of `ml' is (string * ctyp) list. The concept of quotations is to get concrete syntax for abstract terms and then avoid to learn all constructors and types. Alas for some of them you have to know the type. In the new version you can express any term (except one) by concrete syntax. The closest version is: | Object l -> let ml = List.map (fun x -> <:ctyp< $lid:x.field_caml_name$ : $convert x.field_type$ >>) l in <:ctyp< < $list:ml$ > >> Here one doesn't know if methods declarations are a pair or something else and we don't care. Since one knows the syntax << method_name : method_type >>. At this place the list antiquotation $list:ml$ is a sugar for $Ast.tySem_of_list ml$. By changing a little more the code one can use something closer to the object syntax. | Object l -> let ml = List.fold_right (fun x acc -> <:ctyp< $lid:x.field_caml_name$ : $convert x.field_type$ ; $acc$ >>) l <:ctyp<>> in <:ctyp< < $ml$ > >> The general syntax of object types (omiting `..' for the row variable) is < meth1 : type1 ; ... ; methN : typeN > then one can avoid to construct a list (since map is a fold_right with `::') and then call a function that destruct it. Another thing to point out is the use of the nil type <:ctyp<>> that is quite useful to start the folding. In this translation I used both styles depending of the context. The patch: http://gallium.inria.fr/~pouillar/pub/camlp4/rosetta/pa_json_static/pa_json_static.patch The new version (compiles with camlp4orf): http://gallium.inria.fr/~pouillar/pub/camlp4/rosetta/pa_json_static/pa_json_static.ml Cheers, -- Nicolas Pouillard