<div dir="ltr"><div><div><br></div>Yes, you&#39;re right about the type context. I always forget that Functor is not a superclass of Monad. Anyway, the `fmap` can be done only with `Monad` in the context.<br><br></div>About the list fusion, I&#39;m compiling with optimizations enabled (-O2), but I do not know how it works with fusions. Is it the optimization omitting the step of creating the list? How can I know it with certainty?<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jan 25, 2013 at 7:23 AM, Thomas Horstmeyer <span dir="ltr">&lt;<a href="mailto:horstmey@mathematik.uni-marburg.de" target="_blank">horstmey@mathematik.uni-marburg.de</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
isn&#39;t the correct type context for f the following?<br>
<br>
f :: (Functor m, Monad m) =&gt; Int -&gt; m a -&gt; m (Seq a)<br>
<br>
So your f really is a kind of specialization of g.<br>
<br>
Could the reason for f performing better be list fusion? Anything happening inside Control.Monad.replicateM should be subject to it.<br>
<br>
Cheers,<br>
Thomas<br>
<br>
<br>
Am 24.01.2013 15:31, schrieb Daniel Díaz Casanueva:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
Hi Cafe,<br>
<br>
I was coding this morning when I suddenly found something that surprised<br>
me. It&#39;s been a short time since I am really caring about the<br>
performance of my programs. Before, I was just caring about their<br>
correctness. So I am trying different things and profiling to see<br>
differences. One difference I have found surprising is that the function<br>
f is MUCH faster and less space consuming than the function g:<br>
<br>
import Control.Monad<br>
import qualified Data.Sequence as Seq<br>
<br>
type Seq = Seq.Seq<br>
<br>
f :: Monad m =&gt; Int -&gt; m a -&gt; m (Seq a)<br>
f n = fmap Seq.fromList . replicateM n<br>
<br>
g :: Monad m =&gt; Int -&gt; m a -&gt; m (Seq a)<br>
g = Seq.replicateM<br>
<br>
Maybe is just in my test case, where the Int argument is big and the<br>
monadic action short, but it looks to me that Data.Sequence.replicateM<br>
can be faster than it is right now.<br>
<br>
Regards,<br>
Daniel Díaz.<br>
<br>
--<br>
E-mail sent by Daniel Díaz Casanueva<br>
<br>
let f x = x in x<br>
<br>
<br></div></div><div class="im">
______________________________<u></u>_________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/haskell-cafe</a><br>
<br>
</div></blockquote><div class="HOEnZb"><div class="h5">
<br>
______________________________<u></u>_________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br><br clear="all"><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>