A haskell function that takes two strings and filters the second according to the first

2463 views list

So the objective is: Using foldr , define a function remove which takes two strings as its arguments and removes every letter from the second list that occurs in the first list. For example remove "first" "second" = "econd".

if this function took a single character and a string i would do

remove a xs = foldr (\x acc -> if x /= a then x : acc else acc) [] xs

but i cant figure out how i am supposed to do this with two strings. Thank you!

answered question

im stupid... thank you @WillemVanOnsem

1 Answer


remove xs ys = foldr (\x acc -> if elem x xs then acc else x : acc) [] ys


posted this

Have an answer?


Please login first before posting an answer.