I am very new to Haskell and I have a problem. I have a module defined as:
inc :: Int->[Int]->[Int]
What it is supposed to do is to return all occurrences of the first argument in its second argument. So output of 1 [1,1,3]
would return [1,1]
.
This is what I have:
inc :: Int->[Int]->[Int]
inc x [y] = if [x] == [y] then [x] else []
Since I was struggling I just wanted to see if it would work for one number and it does. For instance: 1 [1]
returns [1]
. However, when I attempt you use multiple values such as 1 [1,1]
I receive the error:
Non exhaustive patterns in the function inc
How could I adapt my program, so it is able to handle multiple values instead of just one value?