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 91D2DBC6C for ; Tue, 1 May 2007 09:26:53 +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 l417Qqvx011036 for ; Tue, 1 May 2007 09:26:53 +0200 Received: by nz-out-0506.google.com with SMTP id l8so2311180nzf for ; Tue, 01 May 2007 00:26:52 -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=FcDuaLCNUW6/lLC5S4jpI7RRXOoCQXPkchVY6VqSB8KsNyi9hC7D+FVfPN4DFgxHgerb57piFqFUrZXDRH6uWgNgrBYOnliywtqrJzFx0Oq8r4apNZq+HVdHkX694K7/Mrb6Bm6n9A6Lv/q6RC9fbtChwd7BX+L3fbZlcxEu5Mc= 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=sImLpgv6qpPhJl1Tw0+G2q9ZTlx+MAmra7cFYc2nlnnozF6jGNWlyZyGO749VqUj866oHNaFYgws9LHeTWMbWE1YHqe0HWXKpsg7JheCLS0lqsLqjbqQ2WCQCycZi5w3Kn8f5TzGQeF77Q5rGLB6Ll3YULYCdS+GVqYMgAMKQyE= Received: by 10.114.205.1 with SMTP id c1mr2278731wag.1178004412010; Tue, 01 May 2007 00:26:52 -0700 (PDT) Received: by 10.114.181.18 with HTTP; Tue, 1 May 2007 00:26:51 -0700 (PDT) Message-ID: Date: Tue, 1 May 2007 09:26:51 +0200 From: "Nicolas Pouillard" To: "Joel Reymont" Subject: Re: [Caml-list] camlp4 3.10: Hashtbl.t and <:ctyp< $tp1$ . $tp2$ >> Cc: "Caml List" In-Reply-To: <85C23368-5DC3-4ECB-BEBA-EB98E5140E33@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <85C23368-5DC3-4ECB-BEBA-EB98E5140E33@gmail.com> X-j-chkmail-Score: MSGID : 4636EBBC.000 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 4636EBBC.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlp:01 hashtbl:01 ctyp:01 hashtbl:01 denoting:01 ctyp:01 camlp:01 node:01 wrote:01 rec:01 rec:01 caml-list:01 assert:01 assert:01 strings:01 On 4/30/07, Joel Reymont wrote: > Consider the following function. My understanding is that for, say, > Hashtbl.t it should return a list of types where the 1st element > represents "t" and the second represents "Hashtbl". > > (* [tp_path tp] takes a type. @return a module path (list of strings) > denoting this type. *) > let rec tp_path = function > | <:ctyp< $lid:id$ >> | <:ctyp< $uid:id$ >> -> [id] > | <:ctyp< $tp1$ . $tp2$ >> -> > (match tp_path tp2 with [n] -> n | _ -> assert false) :: > tp_path tp1 > | _ -> invalid_arg "tp_path" > > Nicolas suggested the following approach which doesn't work because > tp1 and tp2 become idents. There's a function to convert from ctyp to > ident but I could not find the opposite from searching the camlp4 > source tree. > > let rec tp_path = function > | <:ctyp< $lid:id$ >> | <:ctyp< $uid:id$ >> -> [id] > | <:ctyp< $id:id$ >> -> > (match id with > | <:ident< $tp1$ . $tp2$ >> -> > (match tp_path tp2 with [n] -> n | _ -> assert false) :: > tp_path tp1 > | _ -> invalid_arg "tp_path") > | _ -> invalid_arg "tp_path" > > Since Hashtbl.t is a valid type, there should be a camlp4 ctyp > pattern to match it, no? > > Am I missing something obvious? To see how is represented something: $ camlp4of -str '<:ctyp< Hashtbl.t >>' Ast.TyId (_loc, Ast.IdAcc (_loc, Ast.IdUid (_loc, "Hashtbl"), Ast.IdLid (_loc, "t"))) So the function tp_path doesn't need to recurse on types since there is only one node which is TyId(_,_) -> <:ctyp< $id:_$ >> let tp_path = function | <:ctyp< $id:path$ >> -> let rec loop = function | <:ident< $i1$.$i2$ >> -> ... | ... in loop path | _ -> fail.... -- Nicolas Pouillard