
19 Nov
2011
19 Nov
'11
3:09 a.m.
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