2

当我在 Haskell 中使用 floor 时,即 floor 1.7 我认为它会给我 1 并且它的类型将是 Int 但我不断收到一条错误消息,好像不是这种情况?

4

1 回答 1

7

对我来说很好:

ghci > floor 1.7
1
ghci > :t floor 
floor :: (Integral b, RealFrac a) => a -> b

您可以通过明确提及类型来强制它成为Int类型:

ghci > floor 1.7 :: Int
1

或者如果你想要Integer

ghci > floor 1.7 :: Integer
1
于 2013-11-17T16:27:52.340 回答