[Haskell-beginners] Int V.S. Word32
Haisheng Wu
freizl at gmail.com
Sat Nov 19 09:09:50 CET 2011
Hello,
I got great performance difference for the following code if I used type
`Int` rather than `Data.Word.Word32`.
Anyone can help to explain why such difference?
Thanks a lot.
-Simon
module Main where
import Data.Word
main :: IO ()
main = print $ p14
p14 = maximum [ (startChain n 0, n) | n <- [2..1000000] ]
startChain :: Word32 -> Int -> Int
startChain 1 count = count + 1
startChain n count = startChain (intTransform n) (count+1)
intTransform :: Word32 -> Word32
intTransform n
| even n = n `div` 2
| otherwise = 3 * n + 1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20111119/9c7f8398/attachment.htm>
More information about the Beginners
mailing list