Browse thread
optimization of sequence of List.map and inlining
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2008-06-10 (22:10) |
From: | Peng Zang <peng.zang@g...> |
Subject: | Re: [Caml-list] optimization of sequence of List.map and inlining |
-----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-----