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.2 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 407EEBBAF for ; Wed, 11 Jun 2008 00:10:14 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkoBAN+YTkhKfS4ddGdsb2JhbACRTUMBDAMEBgcPBZkwhWY X-IronPort-AV: E=Sophos;i="4.27,619,1204498800"; d="scan'208";a="13798493" Received: from yw-out-2324.google.com ([74.125.46.29]) by mail3-smtp-sop.national.inria.fr with ESMTP; 11 Jun 2008 00:10:13 +0200 Received: by yw-out-2324.google.com with SMTP id 5so1539591ywb.3 for ; Tue, 10 Jun 2008 15:10:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:reply-to:to:subject:date :user-agent:cc:references:in-reply-to:content-type :content-transfer-encoding:content-disposition:message-id; bh=w0Bi4CxRlTbIl8k/n4tTmqeKXgw4145sxD+yDTrrC2o=; b=pm/CsDSbh9ei2K1orA5PaY/eHjwhUfl3+MZ1bkh4uVgY1ic85OS6LXrGRRhK+mczyR zsbI+Zm+TAF0zyHQKD46BemHsyL7pFj3uJgb7C+LNsNzCD5rn7HFdNAdGNrxD3pfXGnJ yusG//7clMm1mrjgFLAMR/cfghN4WY6fnstt4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:reply-to:to:subject:date:user-agent:cc:references:in-reply-to :content-type:content-transfer-encoding:content-disposition :message-id; b=bx6vw/tPO6LmpZAJN2aPIdFHg4TiS2NSv6iLqJbJ046KrZFZQHJa4CUx+fO4Etjtva +Lrij6oAhPDhLiK/AYT7EkssmnhXbMYHRtYjs1tXxE18WNN/Qw+gKurigD3sWa2ZmW7h y0qRjNXafORP1TyeBEJalTEhQUPK53U+E+w+c= Received: by 10.151.108.17 with SMTP id k17mr9254773ybm.31.1213135808919; Tue, 10 Jun 2008 15:10:08 -0700 (PDT) Received: from ?192.168.0.102? ( [24.99.180.210]) by mx.google.com with ESMTPS id e27sm7180017elf.3.2008.06.10.15.10.07 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 10 Jun 2008 15:10:08 -0700 (PDT) From: Peng Zang Reply-To: peng.zang@gmail.com To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] optimization of sequence of List.map and inlining Date: Tue, 10 Jun 2008 18:10:03 -0400 User-Agent: KMail/1.9.7 Cc: "Charles Hymans" References: <676aba050806101201x526f03b1lf1fdbed665ee2e3f@mail.gmail.com> In-Reply-To: <676aba050806101201x526f03b1lf1fdbed665ee2e3f@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200806101810.06553.peng.zang@gmail.com> X-Spam: no; 0.00; inlining:01 hash:01 enum:01 enum:01 compiler:01 peng:98 peng:98 40.:98 wrote:01 caml-list:01 lazy:02 data:02 structures:02 optimization:03 module:03 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 ExtLib has an Enum module. It has lazy maps among other things. This means I can perform multiple maps and it will not create intermediate data structures. Example (++ is function composition and $ is function application): Enum.fold (+) 0 ++ Enum.map (( * ) 2) ++ Enum.map ((+) 1) $ List.enum [1;2;3;4;5] Will add one to everything in the list, double it and then sum the list, which yields 40. Peng On Tuesday 10 June 2008 03:01:12 pm 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. > > Thank you, -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.7 (GNU/Linux) iD8DBQFITvu+fIRcEFL/JewRAqmMAJ9rWadpHtt2ZiE8EDn4iIKoASDPegCgi0mM p8iIohGVfxAXXOboMiiNKI4= =XALu -----END PGP SIGNATURE-----