1
我想寫遞歸數函數泰勒:哈斯克爾沒有實例...產生
mcloren x = log (1+x)/(1-x)
compareWithDelta' :: (Num a, Floating a, Integral a, Ord a) => a -> a -> Bool
compareWithDelta' x acc = abs (acc - mcloren x) < 1.0e-10
mcl :: (Floating a, Integral a, Num a) => a -> a
mcl x =
let
mcl' x acc y
| compareWithDelta' x acc = acc
| otherwise = mcl' x (2*(x^(2*y+1)/(2*y+1))) (y+1)
in
mcl' x 0 0
但我有這些錯誤消息:
No instance for (Num a0) arising from a use of 'mcl'
The type variable 'a0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there are several potential instances:
instance Num Double — Defined in 'GHC.Float'
instance Num Float — Defined in 'GHC.Float'
instance Integral a => Num (GHC.Real.Ratio a)
— Defined in 'GHC.Real'
...plus three others
In the expression: mcl 1
In an equation for 'it': it = mcl 1
是什麼意思,以及如何要解決這個問題 ?
我希望GHC能夠爲這種情況指定用戶編程的警告/錯誤。如在「,如果在類型檢查/推理之後,你會發現'Num(a-> b)'表明......」。 – chi