Hmm... I think I made a little confusion so I put my finding here:<div><a href="http://haisgwu.info/posts/2011-11-20-euler-problem-14.html">http://haisgwu.info/posts/2011-11-20-euler-problem-14.html</a></div><div><br></div>

<div>I do got stack overflow thus need several compile opts to fix it.</div><div>Not sure if it is what you mean by &quot;You get overflow using 32-bit types here.&quot;<br><div><br clear="all">-Haisheng<br>
<br><br><div class="gmail_quote">On Sat, Nov 19, 2011 at 10:49 PM, Daniel Fischer <span dir="ltr">&lt;<a href="mailto:daniel.is.fischer@googlemail.com">daniel.is.fischer@googlemail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">On Saturday 19 November 2011, 09:09:50, Haisheng Wu wrote:<br>
&gt; Hello,<br>
&gt;   I got great performance difference for the following code if I used<br>
&gt; type `Int` rather than `Data.Word.Word32`.<br>
&gt;   Anyone can help to explain why such difference?<br>
<br>
</div>Short answer: GHC optimises Int calculations far better than Word32<br>
calculations, rather, it optimises more calculations for Int than for<br>
Word32.  It also optimises more calculations for Word than for Word32, but<br>
not as many as for Int.<br>
<br>
The reason is that Int (and Word) are (at least expected to be) far more<br>
often used, so the effort has gone to these types primarily. Work is being<br>
done to get the fixed-width types on par, but it&#39;s not around the corner<br>
yet.<br>
<br>
You can try using Word instead of Word32, that&#39;s likely to be faster.<br>
<br>
But<br>
<div class="im"><br>
&gt;   Thanks a lot.<br>
&gt;<br>
&gt; -Simon<br>
&gt;<br>
&gt; module Main where<br>
&gt; import Data.Word<br>
&gt;<br>
&gt; main :: IO ()<br>
&gt; main = print $ p14<br>
&gt;<br>
&gt; p14 = maximum [ (startChain n 0, n) | n &lt;- [2..1000000] ]<br>
<br>
</div>You get overflow using 32-bit types here.<br>
<div class="HOEnZb"><div class="h5"><br>
&gt;<br>
&gt; startChain :: Word32 -&gt; Int -&gt; Int<br>
&gt; startChain 1 count    = count + 1<br>
&gt; startChain n count    = startChain (intTransform n) (count+1)<br>
&gt;<br>
&gt; intTransform :: Word32 -&gt; Word32<br>
&gt; intTransform n<br>
&gt;<br>
&gt;   | even n         = n `div` 2<br>
&gt;   | otherwise      = 3 * n + 1<br>
<br>
</div></div></blockquote></div><br></div></div>