【发布时间】:2018-01-20 01:19:40
【问题描述】:
我几乎到处寻找,但找不到以下代码不起作用的原因:
isPrime :: Int -> Bool
isPrime 1 = False
isPrime n = divTest n (floor (sqrt n))
where
divTest :: Int -> Int -> Bool
divTest n test
| test == 1 = True
| mod n test == 0 = False
| otherwise = divTest n (test-1)
我得到了两个错误,它们真的很长,所以我将把我认为重要的部分放在:
No instance for (RealFrac Int) arising from a use of ‘floor’
和
No instance for (Floating Int) arising from a use of ‘sqrt’
是的,我知道这可能没有任何效率。我在学。
【问题讨论】: