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=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 79BF0BBAF for ; Tue, 10 Jun 2008 21:25:15 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmwBAClyTkjUnw7UfGdsb2JhbACCOY9XAQELBQIECREDnyA X-IronPort-AV: E=Sophos;i="4.27,618,1204498800"; d="scan'208";a="13792357" Received: from ptb-relay01.plus.net ([212.159.14.212]) by mail3-smtp-sop.national.inria.fr with ESMTP; 10 Jun 2008 21:25:15 +0200 Received: from [80.229.56.224] (helo=beast.local) by ptb-relay01.plus.net with esmtp (Exim) id 1K69T0-0004U1-7r for caml-list@yquem.inria.fr; Tue, 10 Jun 2008 20:25:14 +0100 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] optimization of sequence of List.map and inlining Date: Tue, 10 Jun 2008 20:21:36 +0100 User-Agent: KMail/1.9.9 References: <676aba050806101201x526f03b1lf1fdbed665ee2e3f@mail.gmail.com> In-Reply-To: <676aba050806101201x526f03b1lf1fdbed665ee2e3f@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200806102021.36680.jon@ffconsultancy.com> X-Plusnet-Relay: 09e1034ca76a634f60f9ca850ed6f828 X-Spam: no; 0.00; inlining:01 compiler:01 mls:01 frog:98 wrote:01 caml-list:01 optimization:03 element:03 let:03 let:03 applied:05 function:08 fun:08 passes:10 runs:11 On Tuesday 10 June 2008 20:01:12 Charles Hymans wrote: > Let's say, I have the following code: > > let f l = List.map succ l > > .... > > let l = f l in > let l = List.map succ l in > do_something_with l > > > Is there a way to tell the compiler to optimize it so that it runs as fast > as this code: > let l = List.map (fun x -> succ (succ x)) l in > l > In the first case, there are two passes where succ is applied to each > elements of the list. > In the second case, there is only one pass that applies succ twice to each > element of the list. In MLs, you deforest by hand. You might like to use a function composition operator like << from F#: let lst = map (f << f) lst -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e