0
votes

Hello im trying to remove elements from a list which applies to my function as such: removeBy even [1..10] → [1,3,5,7,9] or removeBy (=='a' ) ['b' , 'a' ,'c' ] → "bc"

using high order functions like map, foldl, foldr, and filter what i did is

removeBy :: (a -> Bool) -> [a] -> [b]
removeBy function list = map function list 

when i try to run example 1 with even i get

Variable not in scope: removeBy :: (a0 -> Bool) -> [a1] -> t

Anyone can help me?

1
How exactly are you trying to run it? What commands do you type in? Where? - Fyodor Soikin

1 Answers

7
votes

You can just do filter (not . condition) list — that is, negate the condition, i.e. filter all the values which do not satisfy the condition. So e.g. your removeBy (=='a') would be the same as filter (not . (=='a')) — or even simpler, filter (/='a').

As for why your attempted implementation didn’t work: map function list simply applies function to every element of list, and so cannot add or remove any elements.