我收到此錯誤:在Haskell
<interactive>:145:29:
Could not deduce (Integral ([a0] -> Int))
arising from a use of ‘fromIntegral’
from the context (Num ([a] -> a), Fractional a)
bound by the inferred type of
meanList :: (Num ([a] -> a), Fractional a) => [a] -> a
at <interactive>:145:5-50
The type variable ‘a0’ is ambiguous
In the second argument of ‘(/)’, namely ‘(fromIntegral length x)’
In the expression: (sum x)/(fromIntegral length x)
In an equation for ‘meanList’:
meanList x = (sum x)/(fromIntegral length x)
由產生上述錯誤:
然而,當更新這:
let meanList x = sum x/fromIntegral (length x)
然後,所有很好。
括號在Haskell中如何工作?
這不是括號中的問題,而是函數應用。 – AJFarmar
如果有疑問,請添加'$':'fromIntegral $ length x'與fromIntegral(length x)'相同,但不需要跟蹤右括號必須位於何處。 – 9000