我在 Haskell 中编程,但在使用以下代码时遇到问题:
exactRootList :: Int -> Int -> [Int]
exactRootList ini end =
[x | x<-[ini .. end], (floor (sqrt x)) == (ceiling (sqrt x))]
然后,当我执行时:
> hugs myprogram.hs
我明白了
Error Instances of (Floating Int, RealFrac Int) required for definition of exactRootList
我不明白这个错误。
我的程序应该在区间 [a, b] 上显示一个精确根为 4 或 9 的数字列表,其中 a 和 b 是函数的两个参数。例子:
exactRootList 1 10
它必须返回
1 4 9
因为在 1 和 10 之间,只有 1、4 和 9 具有精确根。
问候!