我是Haskell的新手,我的代码不会编译。编写我的第一个Haskell函数的问题
multipleSum :: Int -> Int
multipleSum x = let recSum 0 b = b
recSum a b | a mod 3 == 0 = recSum a-1 b+a
| a mod 5 == 0 = recSum a-1 b+a
| otherwise = recSum a-1 b
in recSum x 0
这些是我得到的两个错误,第一个出现在第3行,第2个出现在第6行。我做错了什么? (该功能应该是3的倍数和5以下n个总和)
1.
Occurs check: cannot construct the infinite type: a ~ a -> a -> a
Expected type: (a -> a -> a) -> a -> a
Actual type: ((a -> a -> a) -> a -> a) -> (a -> a -> a) -> a -> a
Relevant bindings include
b :: (a -> a -> a) -> a -> a
(bound at src\Main.hs:5:30)
a :: (a -> a -> a) -> a -> a
(bound at src\Main.hs:5:28)
recSum :: ((a -> a -> a) -> a -> a)
-> ((a -> a -> a) -> a -> a) -> (a -> a -> a) -> a -> a
(bound at src\Main.hs:4:21)
In the first argument of `(-)', namely `recSum a'
In the first argument of `(+)', namely `recSum a - 1 b'
2.Couldn't match expected type `(a0 -> a0 -> a0) -> a0 -> a0'
with actual type `Int'
In the first argument of `recSum', namely `x'
In the expression: recSum x 0
Couldn't match expected type `Int'
with actual type `(a0 -> a0 -> a0) -> a0 -> a0'
Probable cause: `recSum' is applied to too few arguments
In the expression: recSum x 0
In the expression:
let
recSum 0 b = b
recSum a b
| a mod 3 == 0 = recSum a - 1 b + a
| a mod 5 == 0 = recSum a - 1 b + a
| otherwise = recSum a - 1 b
in recSum x 0