Reputation: 10981
I have this simple method is Haskell
, which dispenses much explanation:
-- 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
[]
I'm getting the following error:
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.
Although I know the logic is sound, I can't figure out what I'm missing here ... could someone please help me out?
Upvotes: 1
Views: 104
Reputation: 656
Change x : ignoreAfter(n-1 xs)
to x : ignoreAfter (n-1) xs
. () are not part of the function application in Haskell. When you passed (n-1 xs)
to ignoreAfter
, it treated it as just one argument. That is why you were getting the Probable cause: ignoreAfter is applied to too few arguments
message.
Upvotes: 4