Haskell中Int(有界整数)的大小是多少,或者我应该在GHC中说什么?
作为练习,我编写了一个简短的程序来获取Int中设置的位数
import Data.Bits
getBits :: Int -> Int
getBits x
| x == 0 = 0
| otherwise = 1 + (getBits y)
where y = x .&. (x - 1)
main = do
putStrLn "type a integer"
num <- getLine
let n = read num :: Int
putStrLn $ "result is: " ++ show (getBits n)
Run Code Online (Sandbox Code Playgroud)
如果输入数字-1,则结果为64,表示Int的大小为64位.为什么会这样?为什么它不像C/C++那样是32位?
haskell ×1