<div dir="ltr"><div><div><div>Hi Cafe,<br><br></div>I was coding this morning when I suddenly found something that surprised me. It&#39;s been a short time since I am really caring about the performance of my programs. Before, I was just caring about their correctness. So I am trying different things and profiling to see differences. One difference I have found surprising is that the function f is MUCH faster and less space consuming than the function g:<br>
<br></div><div><span style="font-family:courier new,monospace">import Control.Monad<br></span></div><span style="font-family:courier new,monospace">import qualified Data.Sequence as Seq<br><br></span></div><div><span style="font-family:courier new,monospace">type Seq = Seq.Seq<br>
</span></div><div><span style="font-family:courier new,monospace"><br></span></div><div><span style="font-family:courier new,monospace">f :: Monad m =&gt; Int -&gt; m a -&gt; m (Seq a)<br>f n = fmap Seq.fromList . replicateM n<br>
<br></span></div><div><span style="font-family:courier new,monospace">g :: Monad m =&gt; Int -&gt; m a -&gt; m (Seq a)<br></span></div><div><span style="font-family:courier new,monospace">g = Seq.replicateM</span><br></div>
<div><div><div><div><br></div>Maybe is just in my test case, where the Int argument is big and the monadic action short, but it looks to me that Data.Sequence.replicateM can be faster than it is right now.<br><br></div><div>
Regards,<br></div><div>Daniel Díaz.<br></div><div><div><br>-- <br><div dir="ltr"><div>E-mail sent by Daniel Díaz Casanueva<br></div><div><div><br>let f x = x in x<br></div></div></div>
</div></div></div></div></div>