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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 17F98BC6C for ; Fri, 18 Jan 2008 20:54:29 +0100 (CET) X-IronPort-AV: E=Sophos;i="4.25,218,1199660400"; d="scan'208";a="21488017" Received: from peray.inria.fr (HELO ausone.inria.fr) ([128.93.8.98]) by mail4-relais-sop.national.inria.fr with SMTP; 18 Jan 2008 20:54:28 +0100 Received: by ausone.inria.fr (sSMTP sendmail emulation); Fri, _d Jan 2008 20:53:27 +0100 From: "Nicolas Pouillard" Content-Type: text/plain; charset=UTF-8 Cc: christian.sternagel , caml-list Subject: Re: [Caml-list] camlp4 To: oandrieu References: <1200676132.4790dd24bfca9@web-mail2.uibk.ac.at> <95513600801181130u2f6584b8w505cd10e848bcc65@mail.gmail.com> In-Reply-To: <95513600801181130u2f6584b8w505cd10e848bcc65@mail.gmail.com> Date: Fri, 18 Jan 2008 20:53:27 +0100 Message-Id: <1200685853-sup-3987@ausone.local> User-Agent: Sup/git X-Spam: no; 0.00; camlp:01 camlp:01 flatten:01 appends:01 syntax:01 recursive:01 oandrieu:01 ocaml:01 wrote:01 preprocessor:01 caml-list:01 tail:01 nerim:01 variables:02 variables:02 Excerpts from oandrieu's message of Fri Jan 18 20:30:59 +0100 2008: > On Jan 18, 2008 6:08 PM, Christian Sternagel > wrote: > > When using `camlp4o -parser Camlp4ListComprehension' as preprocessor, > > is the resulting code the naive translation, like in, > > > > [(x, y) | x <- xs, even xs, y <- ys] > > > > => > > > > List.flatten ( > > List.map (fun x -> List.map (fun y -> (x, y)) ys) (List.filter even xs) > > ) > > > > or is there an optimization in order to avoid appends and minimize the > > number of cons? > > > FYI, my (old) syntax extension¹ for camlp4 <= 3.09 expands list > comprehensions to a combination of folds: > > [+ (x, y) | x <- xs | when even x | y <- ys] > > => > > List.fold_right > (fun x __acc__ -> > if even x then > List.fold_right (fun y __acc__ -> (x, y) :: __acc__) ys __acc__ > else __acc__) > xs [] > > Less cons operations, but it's not tail recursive. Hum... That's nice and I could accept patches in that direction. However can you do it without introducing variables, that's always dangerous to add variables because we should check that the user is not using the same. > [1] http://oandrieu.nerim.net/ocaml/#pa_compr -- Nicolas Pouillard aka Ertai