I want to define a Haskell function that removes from a list of strings any string contained in a pair of strings and returns only a list that contains all the remaining strings. So an example would be:
function ["football","basketball","soccer"] ("football", "basketball") = ["soccer"]
I know you can use the filter function to filter list that satisfy the predicate given. I know that I can filter out a list in this manner:
function' xs s = filter (/=s) xs
But I can’t figure out how to get this to work with tuples. I keep getting errors when I run the code. Any idea how to do this? Thanks
Lets see type of
filterWhen you do
filter f xs,it just applies the function
fof typea -> Boolon all the elements of the list removing those for which this function returnsFalse.I have pattern matched on elements of the tuple as
(a,b)and I just defined functionfas\x -> (x /= a) && (x /= b). This is an anonymous function which takes an element of the list and returnsTrueonly when it is neither equal to first element of the tuple nor equal to the second element.&&is booleanandso it returnsTrueonly when both its arguments areTrue.