你好,我最近开始学习Haskell和我试图做的是给它创建了一个功能列表的小程序,然后我想利用列表的总和:试图从生成的列表总结
f a b c = a+b+c
my_sum [] = 0
my_sum (x:xs) = x + my_sum xs
my_list f a b c = [f a b x |x <- [1..c]]
我试图采取列表的总和是这样,但你能帮助我,我总是得到错误
*Main> my_sum [my_list f 1 1 4]
<interactive>:13:1:
No instance for (Num [t0]) arising from a use of `my_sum'
Possible fix: add an instance declaration for (Num [t0])
In the expression: my_sum [my_list f 1 1 4]
In an equation for `it': it = my_sum [my_list f 1 1 4]
<interactive>:13:9:
No instance for (Num t0) arising from a use of `my_list'
The type variable `t0' is ambiguous
Possible fix: add a type signature that fixes these type variabl
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: my_list f 1 1 4
In the first argument of `my_sum', namely `[my_list f 1 1 4]'
In the expression: my_sum [my_list f 1 1 4]
?
有什么错误? – Khaelid
'my_list'有5个参数,但你只提供4. – Lee
@Khaelid我编辑了这个问题。我复制了我的代码的错误版本。 – JmRag