【发布时间】:2011-05-21 07:40:27
【问题描述】:
我有一个函数接受 2 个整数 n、x,并计算下限 (log n/log x)。这里 n 和 x 都非常有限,所以 Int 对我来说就足够了。
func :: Int -> Int -> Int
func n x = floor (log . fromIntegral n / (log . fromIntegral x))
但这里出现了 ghci 中的错误:
No instance for (RealFrac (a -> b))
arising from a use of `floor' at p5_evenly_divide.hs:20:11-63
Possible fix: add an instance declaration for (RealFrac (a -> b))
In the expression:
floor (log . fromIntegral n / (log . fromIntegral x))
In the definition of `func':
func n x = floor (log . fromIntegral n / (log . fromIntegral x))
我该如何度过这个难关?
【问题讨论】:
标签: haskell floating-point int