So here I have the following on GHCI
>let addlist [] [] = []
>let addlist (a:as) (b:bs) = (a+b) : addlist as bs
>let x = [1..5]
>let y = [6..10]
>addlist x y
The last line gives me:
[7,9,11,13,15*** Exception: :1:5-49: Non-exhaustive patterns in function addlist
I am merely trying to add two list together into one list…:(
What did I do wrong?
Thanks
If you want to define a function using pattern matching inside a
let, you can’t use one let per pattern as you did – that will simply define two independent functions (the second one shadowing the first).You need to use a single let and separate the patterns using linebreaks or, in ghci where you can’t use linebreaks, semicolons. So: