我试图模拟e ^ x的泰勒多项式
---Macularian for e^x
e :: (Num a) => a -> Int -> a
e value precsion = sum $ take precsion [((x^n) / product [1..n]) | x <- value, n <- [0..]]
这是我的错误
Main.hs@3:73-3:78无法从上下文中推断出(a~ [a])(Num a) 由e :: Num a =&gt;的类型签名绑定a - &gt; Int - &gt;一个在 /home/app/isolation-runner-work/projects/75872/session.207/src/Main.hs:2:6-29 a是由e :: Num a的类型签名绑定的刚性类型变量 =&GT; a - &gt; Int - &gt; a at /home/app/isolation-runner-work/projects/75872/session.207/src/Main.hs:2:6 相关绑定包括value :: a(绑定为 /home/app/isolation-runner-work/projects/75872/session.207/src/Main.hs:3:3) e :: a - &gt; Int - &gt; a(以...结束 /home/app/isolation-runner-work/projects/75872/session.207/src/Main.hs:3:1) ...
答案 0 :(得分:5)
此部分:x <- value
表示value
是一个列表。如果您将其更改为let x = value
(或只是将value
重命名为x
,您将修复该特定编译错误:
e x precision = take precision [ ...formula involving x and n... | n <- [0..] ]
然后您可能会遇到涉及您的类型签名的另一个编译器错误,因此我会对其进行注释,然后让ghci
使用:type
命令告诉您签名应该是什么。