I am trying to implement a function that sums the contents of two lists. Here is my code:
sum'' :: Num a => [a] -> [a] -> [a]
sum'' [] [] = []
sum'' (x:xs) (y:ys) = (x + y) : sum'' xs ys
If I type in:
sum'' [1,2,3] [4,5,6]
I get [5,7,9], which is what I want. What I am having trouble with is different list sizes. If I type in:
sum'' [] [1,2,3]
I want it to return []. Or
sum'' [1,2] [4,5,6]
I want it to return [5,7]. I am getting this error and do not know why: Non-exhaustive patterns in function sum''.
Any help would be much appreciated.
-Wallflag makes GHC warn about the missed cases at compile time. Recommended.