<br><br><div class="gmail_quote">On Mon, Nov 2, 2009 at 2:40 PM, Will Ness <span dir="ltr">&lt;<a href="mailto:will_n48@yahoo.com">will_n48@yahoo.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Jason Dagit &lt;dagit &lt;at&gt; <a href="http://codersbase.com" target="_blank">codersbase.com</a>&gt; writes:<br>
<div class="im"><br>
&gt; On Mon, Nov 2, 2009 at 1:59 PM, Will Ness &lt;will_n48 &lt;at&gt; <a href="http://yahoo.com" target="_blank">yahoo.com</a>&gt; wrote:<br>
&gt; Will Ness &lt;will_n48 &lt;at&gt; <a href="http://yahoo.com" target="_blank">yahoo.com</a>&gt; writes:<br>
&gt;<br>
</div><div class="im">&gt; One _crucial_ tidbit I&#39;ve left out: _type_signature_.<br>
&gt; Adding (:: [Int]) speeds this code up more than TWICE!<br>
&gt; :) :)<br>
&gt;<br>
&gt;<br>
&gt; If you are okay with Int, then maybe you&#39;re also happy with Int32 or Word32.<br>
 If so, why don&#39;t you use template haskell to build the list at compile time?<br>
 If you do that, then getting the kth prime at run-time is O(k).  Take that<br>
 AKS!  :)<br>
&gt;<br>
<br>
<br>
</div>O(k), I&#39;ve removed it since the post actually. Wasn&#39;t thinking clearly for a<br>
moment, having seen the double speedup!<br></blockquote><div><br></div><div>By the way, do you understand where the speedup with Int is coming from?  As I understand it, there are two main places.  One is that the type class dictionary passing can be removed (GHC might figure this out already, I&#39;d need to check the core to be sure).  The other is that GHC is likely unboxing to it&#39;s primitive Int# type.</div>
<div><br></div><div>If none of that made sense, or you&#39;d like to know how you can double check what I&#39;m talking about, then Real-World Haskell has a chapter with an example:</div><div><a href="http://book.realworldhaskell.org/read/profiling-and-optimization.html">http://book.realworldhaskell.org/read/profiling-and-optimization.html</a></div>
<div><br></div><div>Good luck!</div><div>Jason</div></div>