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 F0482BC69 for ; Tue, 1 May 2007 14:47:52 +0200 (CEST) Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.226]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l41CloC0018809 for ; Tue, 1 May 2007 14:47:51 +0200 Received: by nz-out-0506.google.com with SMTP id l8so2366234nzf for ; Tue, 01 May 2007 05:47:49 -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=EmMyTLuQry7VquBH2LzF+Jun8SUu97VTCko1DaSmVZ5qwD81GBMm1wUgZBtDbzzLCr2tZJKCpK2nogc1ZewTPiOZrir97q2ZcGfocmHl6bVaVSeR4xP/H8syjfmtWKJW+jqleLIFC/0PxrE1D6YHdoRMQQIhqldFcxJErkce9FY= 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=mXFVVZBLhBV03M3obFUzZpWQU2T+LJrPoQZFTGs798p8uYE+HH7+5+CKPtvcb51bQ6N5683YBTL3yjuYYhWnJ3+WYLcSKe2QEYAUvQQS3hrHRLlqS9eH4ZKTd1g1k0e0dG0MC4euLYdPImHPrVrE+TY5wiLJFW29ttL+XMyRXrw= Received: by 10.114.161.11 with SMTP id j11mr148363wae.1178023669255; Tue, 01 May 2007 05:47:49 -0700 (PDT) Received: by 10.114.183.15 with HTTP; Tue, 1 May 2007 05:47:49 -0700 (PDT) Message-ID: Date: Tue, 1 May 2007 14:47:49 +0200 From: "Nicolas Pouillard" To: "Joel Reymont" Subject: Re: [Caml-list] camlp4 3.10: <:ctyp< ( $list:tys$ ) Cc: "Caml List" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-j-chkmail-Score: MSGID : 463736F6.000 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 463736F6.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlp:01 ctyp:01 ctyp:01 camlp:01 parens:01 node:01 wrote:01 constructor:01 caml-list:01 tuples:01 int:01 int:01 expression:02 ast:02 ast:02 On 5/1/07, Joel Reymont wrote: > This is the old code: > > | <:ctyp< ( $list:tys$ ) >> -> tupl _loc (List.map aux tys) > > I figure it tries to match something like "int * int". > > Following Nicolas's suggestion I thought I would see what this > expands to: > > camlp4of -str '<:ctyp< ( int * int ) >>' > Ast.TyTup (_loc, > Ast.TySta (_loc, Ast.TyId (_loc, Ast.IdLid (_loc, "int")), > Ast.TyId (_loc, Ast.IdLid (_loc, "int")))) > > How do I work back from this to the right expression within parens in > the original pattern above? I tried > > | <:ctyp< ( $tup:tys$ ) >> -> tupl _loc (List.map aux tys) > > but this produces ctyp instead of ctyp list so it's not suitable for > the tupl. > There is one simple answer about camlp4 AST. There is no more lists inside. Then how to guess, how to pattern match these AST. Take tuples for instance... ( t1 * ... * tN ) Hum that a list of types separated by stars, so in camlp4 the constructor node will be the star. t ::= ... | ( $tup:t$ ) | $t1$ * $t2$ So that's the representation. Now if you really want a list you can use a function like Ast.ctyp_of_list match t with | <:ctyp< ( $tup:t$ ) >> -> Ast.ctyp_of_list t ... Regards, -- Nicolas Pouillard