相关疑难解决方法(0)

Haskell Int大小

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
推荐指数
2
解决办法
2080
查看次数

标签 统计

haskell ×1