我正在尝试做一个haskell one-liner来计算e^x的泰勒级数:
-- 1 + x^1/1! + x^2/2! + x^3/3! + ...
expt x = [(x^e) / (product [1..n]) | e <- [0..], n <- [1..e]]
但我一直遇到这个问题:
<interactive>:5:1:
No instance for (Integral t0) arising from a use of `expt'
The type variable `t0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there are several potential instances:
instance Integral Int -- Defined in `GHC.Real'
instance Integral Integer -- Defined in `GHC.Real'
instance Integral GHC.Types.Word -- Defined in `GHC.Real'
In the expression: expt 2
In an equation for `it': it = expt 2
<interactive>:5:6:
No instance for (Num t0) arising from the literal `2'
The type variable `t0' 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 first argument of `expt', namely `2'
In the expression: expt 2
In an equation for `it': it = expt 2
我不认为我完全理解这里出了什么问题 - 有人可以向我解释一下吗?