[Haskell-cafe] How to remove all numbers from a list that are divisible by an integer

Neil Mitchell ndmitchell at gmail.com
Mon Feb 5 13:27:52 EST 2007

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.



More information about the Haskell-Cafe mailing list