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=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id ACF92BC6B for ; Tue, 22 Jan 2008 14:33:57 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAANN/lUeK6AGOn2dsb2JhbACQFwEBAQEBBgQGCQgYm3I X-IronPort-AV: E=Sophos;i="4.25,233,1199660400"; d="scan'208";a="6400295" Received: from lmr1.uibk.ac.at (HELO smtp.uibk.ac.at) ([138.232.1.142]) by mail2-smtp-roc.national.inria.fr with ESMTP; 22 Jan 2008 14:33:57 +0100 Received: from smc.uibk.ac.at (smc.uibk.ac.at [138.232.1.226] c703350@smc.uibk.ac.at) by smtp.uibk.ac.at (8.13.8/8.13.8/F1) with ESMTP id m0MDXt1L002194 for ; Tue, 22 Jan 2008 14:33:55 +0100 Received: from smc.uibk.ac.at (localhost [127.0.0.1] c703350@smc.uibk.ac.at) by smc.uibk.ac.at (8.13.8+Sun/uibk) with ESMTP id m0MDXtH0015619 for ; Tue, 22 Jan 2008 14:33:55 +0100 (MET) Received: (from c703350@localhost) by smc.uibk.ac.at (8.13.8+Sun/8.13.8/Submit) id m0MDXtjD015618 for caml-list@yquem.inria.fr; Tue, 22 Jan 2008 14:33:55 +0100 (MET) Date: Tue, 22 Jan 2008 14:33:55 +0100 From: Christian Sternagel To: caml-list Subject: Re: [Caml-list] camlp4 Message-ID: <20080122133355.GI3862@pc6197-c703.uibk.ac.at> Mail-Followup-To: caml-list References: <1200676132.4790dd24bfca9@web-mail2.uibk.ac.at> <95513600801181130u2f6584b8w505cd10e848bcc65@mail.gmail.com> <1200685853-sup-3987@ausone.local> <1200755341.4792128d5dad6@web-mail2.uibk.ac.at> <1200842484-sup-3237@ausone.local> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1200842484-sup-3237@ausone.local> User-Agent: Mutt/1.4.2.3i X-Scanned-By: MIMEDefang 2.61 at uibk.ac.at on 138.232.1.140 X-Spam: no; 0.00; camlp:01 wadler:01 expr:01 expr:01 camlp:01 syntax:01 syntax:01 cheers:01 abstract:01 rec:01 rec:01 caml-list:01 patt:01 patt:01 grammar:02 > > How about the transformation from Chapter 7 of [1] (by Philip Wadler)? > > It should be similar to the `pseudo code': > > > > type expr = ...;; > > type patt = ...;; > > type qualifier = Gen of patt * expr | Filt of expr;; > > type compr = (expr * qualifier list);; > > let rec expr = function > > | ... > > | (e, qs) -> transform [] (e, qs) > > | ... > > and transform l = function > > | (e, []) -> expr e :: expr l > > | (e, Filt f :: qs) -> if expr f then transform l (e, qs) else expr l > > | (e, Gen (p, l1) :: qs) -> > > let rec h = function > > | [] -> expr l > > | u :: us -> (function p -> transform (h us) (e, qs) | _ -> h us) u > > in h (expr l1) > > ;; > > > > (* where h, u, us are fresh variables not occurring in e, l1, l, or qs *) > > > > Sorry I'm not yet familiar with camlp4 grammar extensions, but of course > > above code would make use of them otherwise. > > Yes this approach can be integrated with a camlp4 extension. > > > It is stated in [1] that the resulting code is optimal in that it > > performs the minimum number of cons operations. > > Nice. > > > And I did ignore the hint that fresh variables make things > > complicated :). > > Yes it can... > > Best regards, > > -- > Nicolas Pouillard aka Ertai > I deduce that there is no standard way of introducing `fresh' (w.r.t. the abstract syntax tree) variables within a camlp4 syntax extension? Wouldn't that be nice? =) Has anybody every implemented a solution to that problem? cheers christian