My guess is that Cont plays really nicely with GHC&#39;s inliner, so things that end up looking like<br><br> return x &gt;&gt;= \y -&gt; ...<br><br>get optimized really well<br><br>    return x &gt;&gt;= f<br>    -- inline &gt;&gt;=<br>

    = ContState $ \s0 k -&gt; runCS (return x) s0 $ \a s1 -&gt; runCS (f a) s1 k<br>    -- inline return<br>    = ContState $ \s0 k -&gt; runCS (ContState $ \s2 k2 -&gt; k2 x s2) s0 $ \a s1 -&gt; runCS (f a) s1 k<br>    -- runCS record selector<br>
    = ContState $ \s0 k -&gt; (\s2 k2 -&gt; k2 x s2) s0 $ \a s1 -&gt; runCS (f a) s1 k<br>    -- beta<br>    = ContState $ \s0 k -&gt; (\k2 -&gt; k2 x s0) $ \a s1 -&gt; runCS (f a) s1 k<br>   
-- beta<br>    = ContState $ \s0 k -&gt; (\a s1 -&gt; runCS (f a) s1 k) x s0<br>    -- beta<br>    = ContState $ \s0 k -&gt; runCS (f x) s0 k<br><br>and then further inlining of f can take place.<br>
<br><div class="gmail_quote">On Mon, Sep 26, 2011 at 4:07 PM, Nicu Ionita <span dir="ltr">&lt;<a href="mailto:nicu.ionita@acons.at">nicu.ionita@acons.at</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hello list,<br>
<br>
Starting from this emails (<a href="http://web.archiveorange.com/archive/v/nDNOvSM4JT3GJRSjOm9P" target="_blank">http://web.archiveorange.com/<u></u>archive/v/nDNOvSM4JT3GJRSjOm9P</a><u></u>) I could refactor my code (a UCI chess engine, with complex functions, in which the search has a complex monad stack) to run twice as fast as with even some hand unroled state transformer! So from 23-24 kilo nodes per second it does now 45 to 50 kNps! And it looks like there is still some improvement room (I have to play a little bit with strictness annotations and so on).<br>

<br>
(Previously I tried specializations, then I removed a lot of polimorphism, but nothing helped, it was like hitting a wall.)<br>
<br>
Even more amazingly is that I could program it although I cannot really understand the Cont &amp; ContT, but just taking the code example from Ryan Ingram (newtype ContState r s a = ...) and looking a bit at the code from ContT (from the transformers library), and after fixing some compilation errors, it worked and was so fast.<br>

<br>
I wonder why the transformers library does not use this kind of state monad definition. Or does it, and what I got is just because of the unrolling? Are there monad (transformers) libraries which are faster? I saw the library kan-extensions but I did not understand (yet) how to use it.<br>

<br>
Nicu<br>
<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>
</blockquote></div><br>