How to remove all numbers from a list that are divisible by an integer

Hi, Thanx to all for the previous hints how to solve and write the function to calculate the sum of a list of lists. Now I need to know how to remove all numbers that are divisable by an integer. Lets say I have a list [2,4,5,6,8] and when I divide them with number 2, my list should look like [5]...because all other numbers in this list are divisible with 2 therefore I remove or filter all of them. I tried to use some zipWith...filter and other predefined functions..but I can't really find the right solution :(

Hi Miranda,
Now I need to know how to remove all numbers that are divisable by an integer.
Is this a homework problem? Is there some bigger goal you are trying to achieve?
I tried to use some zipWith...filter and other predefined functions..but I can't really find the right solution :(
Can you perhaps show us some of the solutions you tried, so we can see what direction you were going in? It's easy enough to give you the answer, but it's probably beneficial to you if we help you learn these things for yourself. Thanks Neil

Hi all, I'm trying to create a function which filters out all number from a list that are divisible by an integer. Ex. the list [2,3,4,5,6] div 2...should give me the list like: [3,5], other numbers should be removed divisible by 2. filter :: (a -> Bool) -> [a] -> [a] filter p [] = [] filter p (x:xs) = if p 'mod' x then x : filter p xs else filter p xs I tried this, but it doesn't work!!!! Thank You, Miranda

Hi Miranda,
filter :: (a -> Bool) -> [a] -> [a] filter p [] = [] filter p (x:xs) = if p 'mod' x then x : filter p xs else filter p xs I tried this, but it doesn't work!!!!
You are mixing a few things together. First point, mod should be `mod` and not 'mod' - ' means character, ` means infix operator as a name. Second point you can only if test on a Bool, mod returns an Int. Third, filter is an already defined function, if you look up it's source you'll see how you can use this in your program. If you were to hop onto Haskell IRC I'm sure you could get these problems resolved quickly - http://haskell.org/haskellwiki/IRC_channel - you seem to have roughly the basic idea behind the algorithm, its just lots of little details. Perhaps working through a Haskell tutorial would help you clarify these things. Thanks Neil
participants (2)
-
Miranda Kajtazi
-
Neil Mitchell