【发布时间】:2021-07-18 08:18:43
【问题描述】:
您好,我是 Haskell 的新手,想知道是否有人可以教我除法以及为什么我的代码不起作用。任何帮助/批评表示赞赏
grades :: Int -> Int -> Int -> Int -> [Int]
grades a x y z =[(fromIntegral(a-x) / fromIntegral (x)) * fromIntegral(100)]
我希望我的代码计算从 x 到 a 的百分比增加,然后将其返回到列表中。
错误:
No instance for (Fractional Int) arising from a use of `/'
* In the first argument of `(*)', namely
`(fromIntegral (a - x) / fromIntegral (x))'
In the expression:
(fromIntegral (a - x) / fromIntegral (x)) * fromIntegral (100)
In the expression:
[(fromIntegral (a - x) / fromIntegral (x)) * fromIntegral (100)]
【问题讨论】:
标签: list haskell integer typeerror division