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 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 27FF7BC6C for ; Fri, 18 Jan 2008 20:31:01 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAESMkEdA6ba9kGdsb2JhbACQFAEBAQEHBAQJChEHlg6HaQ X-IronPort-AV: E=Sophos;i="4.25,218,1199660400"; d="scan'208";a="21487603" Received: from nf-out-0910.google.com ([64.233.182.189]) by mail4-smtp-sop.national.inria.fr with ESMTP; 18 Jan 2008 20:31:00 +0100 Received: by nf-out-0910.google.com with SMTP id e27so100985nfd.13 for ; Fri, 18 Jan 2008 11:31:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=tax86KBLKS6oXy7BBJS5r6hNFuB+oF4BODE7t92/nT4=; b=c+XlYXU3vWzPow/9gG7oLBCzrm2mu6q3t07EhztyWtI3Vi/CgslK2cjVIlEuZkBlnFN9RdYYeLvbN3sNHjZeNi36Xmjgm1gtf2ckP2DcqzC40SUVbo++h95nvinsTEas2lb20yD1UTZQgLdPlPdxMWIODdWW4HdxbOQWMsmawa0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=qGiEVrPQ2qaMBCg/KSVWkkqjagedvfJJPCjbeaS7IDwU7mpJZCa77yvMPE7rmYQP3P+KKgN9xnBvEQeGa0vSTU923daoKIUW4Dpw6oeAI0p5V3RrSwFAOhliumL3lysF7rveAhnBTgRoCypTw8m+3384TES1kYRWUwGNQ73ZMtM= Received: by 10.78.168.1 with SMTP id q1mr5323526hue.71.1200684659272; Fri, 18 Jan 2008 11:30:59 -0800 (PST) Received: by 10.78.77.18 with HTTP; Fri, 18 Jan 2008 11:30:59 -0800 (PST) Message-ID: <95513600801181130u2f6584b8w505cd10e848bcc65@mail.gmail.com> Date: Fri, 18 Jan 2008 20:30:59 +0100 From: "Olivier Andrieu" Sender: oandrieu@gmail.com To: "Christian Sternagel" Subject: Re: [Caml-list] camlp4 Cc: caml-list@yquem.inria.fr In-Reply-To: <1200676132.4790dd24bfca9@web-mail2.uibk.ac.at> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <1200676132.4790dd24bfca9@web-mail2.uibk.ac.at> X-Google-Sender-Auth: ea78961bcf17964e X-Spam: no; 0.00; andrieu:01 oandrieu:01 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 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] > > =3D> > > 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=B9 for camlp4 <=3D 3.09 expands list comprehensions to a combination of folds: [+ (x, y) | x <- xs | when even x | y <- ys] =3D> 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. [1] http://oandrieu.nerim.net/ocaml/#pa_compr --=20 Olivier