<div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div class="h5">&gt;&gt;&gt;  During a small project I&#39;m trying to develop a small application. It<br>


&gt;&gt;&gt; becomes quite often that I need a function mapapp:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; mapapp _ [] ap = ap<br>
&gt;&gt;&gt; mapapp f (a:as) ap = f a : map f as ap<br></div></div></blockquote><div> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div><div class="h5">&gt;&gt;  Of course,<br>
&gt;&gt;&gt; (map f list) ++ append<br>
&gt;&gt;&gt;  would do the same as<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; mapapp f list append<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;  but with less efficiency. Or am I wrong?<br>
</div></div></blockquote><div><br>I timed each of the following five operations with ...<br><br>&gt; ghc -O2 --make MapApp.hs<br>&gt; time ./MapApp<br><br>... and they produced no statistically significant differences. Each ran for about 3.8 seconds. Perhaps you can try it to convince yourself?<br>

<br>Sean<br><br>--<br><br>module Main where<br><br>mapapp0 :: (a -&gt; b) -&gt; [b] -&gt; [a] -&gt; [b]<br>mapapp0 f tail xs = map f xs ++ tail<br><br>mapapp1 :: (a -&gt; b) -&gt; [b] -&gt; [a] -&gt; [b]<br>mapapp1 _ tail []     = tail<br>

mapapp1 f tail (a:as) = f a : mapapp1 f tail as<br><br>mapapp2 :: (a -&gt; b) -&gt; [b] -&gt; [a] -&gt; [b]<br>mapapp2 f tail = go<br>  where<br>    go []     = tail<br>    go (x:xs) = f x : go xs<br><br>mapapp3 :: (a -&gt; b) -&gt; [b] -&gt; [a] -&gt; [b]<br>

mapapp3 f tail = foldr ((:) . f) tail<br><br>main = do<br>  writeFile &quot;/dev/null&quot; $ show $ [1 .. 10001000]<br>  -- writeFile &quot;/dev/null&quot; $ show $ mapapp0 (+3) [1 .. 10000000] [1 .. 1000]<br>  -- writeFile &quot;/dev/null&quot; $ show $ mapapp1 (+3) [1 .. 10000000] [1 .. 1000]<br>

  -- writeFile &quot;/dev/null&quot; $ show $ mapapp2 (+3) [1 .. 10000000] [1 .. 1000]<br>  -- writeFile &quot;/dev/null&quot; $ show $ mapapp3 (+3) [1 .. 10000000] [1 .. 1000]<br>  return ()<br></div></div>