I'm new to functional programming and haskell, so I'm just starting out learning both by attempting some Euler problems. This involves a great deal of list summations.
So I'm trying to write a recursive list summation function that takes one list as input and returns an integer as output, for instance:
-- Sum up a list
listsum :: [int] -> int
listsum [a:b:[]] = a + b
listsum x = head x + listsum tail x
When compiling this code, I receive this error:
Couldn't match expected type `[[int] -> int]'
with actual type `[a0] -> [a0]'
Relevant bindings include
x :: [int]
(bound at C:\Users\Rade\Documents\GitHub\haskell\euler_2.hs:15:9)
listsum :: [int] -> int
(bound at C:\Users\Rade\Documents\GitHub\haskell\euler_2.hs:14:1)
Probable cause: `tail' is applied to too few arguments
In the first argument of `listsum', namely `tail'
In the second argument of `(+)', namely `listsum tail x'
I've tried to research the pattern matching, but I cannot understand what it means with expected type versus actual type. Where am I going wrong?