预期类型不同于实际类型 - Haskell

时间:2014-10-05 16:44:41

标签: haskell

我有这个简单的方法是Haskell,它解释了很多解释:

-- IgnoreAfter problem: ignoreAfter 3 [7,8,9,3,4,5] == [7,8,9].
ignoreAfter 0 xs = []
ignoreAfter n (x:xs) = if length((x:xs)) >= n then
                           x : ignoreAfter(n-1 xs)
                       else
                          []

我收到以下错误:

pattern_matching.hs:19:32:
    Couldn't match expected type `[a0]' with actual type `[a0] -> [a0]'
    In the return type of a call of `ignoreAfter'
    Probable cause: `ignoreAfter' is applied to too few arguments
    In the second argument of `(:)', namely `ignoreAfter (n - 1 xs)'
    In the expression: x : ignoreAfter (n - 1 xs)
Failed, modules loaded: none.

虽然我知道逻辑是合理的,但我无法弄清楚我在这里失踪了什么......有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:4)

x : ignoreAfter(n-1 xs)更改为x : ignoreAfter (n-1) xs。 ()不是Haskell中函数应用程序的一部分。当您将(n-1 xs)传递给ignoreAfter时,它将其视为一个参数。这就是你收到Probable cause: ignoreAfter is applied to too few arguments消息的原因。