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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id DADDFBC6C for ; Fri, 18 Jan 2008 19:57:48 +0100 (CET) X-IronPort-AV: E=Sophos;i="4.25,217,1199660400"; d="scan'208";a="6292941" Received: from peray.inria.fr (HELO ausone.inria.fr) ([128.93.8.98]) by mail2-relais-roc.national.inria.fr with SMTP; 18 Jan 2008 19:57:51 +0100 Received: by ausone.inria.fr (sSMTP sendmail emulation); Fri, _d Jan 2008 19:56:47 +0100 From: "Nicolas Pouillard" Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] camlp4 To: caml-list References: <1200676132.4790dd24bfca9@web-mail2.uibk.ac.at> In-Reply-To: <1200676132.4790dd24bfca9@web-mail2.uibk.ac.at> Date: Fri, 18 Jan 2008 19:56:47 +0100 Message-Id: <1200682604-sup-4908@ausone.local> User-Agent: Sup/git X-Spam: no; 0.00; camlp:01 camlp:01 flatten:01 appends:01 syntax:01 qualifiers:01 preprocessor:01 caml-list:01 optimization:03 concat:03 concat:03 naive:03 cons:04 translate:04 aka:04 Excerpts from christian.sternagel's message of Fri Jan 18 18:08:52 +0100 2008: > 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? There is only a few very local optimizations. However you can answer to your question by asking camlp4 to translate your code and pretty-print the result. $ camlp4o -parser Camlp4ListComprehension -str '[(x, y) | x <- xs; even xs; y <- ys]' List.concat (List.map (fun x -> List.map (fun y -> (x, y)) ys) (List.filter (fun x -> even xs) xs)) As you can see List.concat is still there. Note also that the syntax is to use `;' to separate qualifiers (generators and filters) instead of `,' as your example. Best regards, -- Nicolas Pouillard aka Ertai