我遇到了一些问题,我新来的一个函数是fromIntegral函数。Haskell将Int转换为Floating
基本上我需要采取两个int参数和返回数字的百分比,但是当我运行我的代码,它不断给我这个错误:
代码:
percent :: Int -> Int -> Float
percent x y = 100 * (a `div` b)
where a = fromIntegral x :: Float
b = fromIntegral y :: Float
错误:
No instance for (Integral Float)
arising from a use of `div'
Possible fix: add an instance declaration for (Integral Float)
In the second argument of `(*)', namely `(a `div` b)'
In the expression: 100 * (a `div` b)
In an equation for `percent':
percent x y
= 100 * (a `div` b)
where
a = fromIntegral x :: Float
b = fromIntegral y :: Float
我读了'98 Haskell前奏,它说有这样一个函数叫fromInt,但它从来没有工作,所以我不得不这样做,但它仍然无法正常工作。帮帮我!
我怀疑98报告称有一个fromInt。 – augustss 2012-04-24 18:04:33