简体   繁体   中英

Haskell function won't work, what am i doing wrong?

Hi i am trying to remove all multiples of m from a list (ex [2..100])

my Code:

crossOut :: Int -> [Int] -> [Int]
crossOut n ns = [ x | x <- ns , x /= (n*x)]

x /= (n*x) tests if x is n times itself, which isn't going to work. Try x `mod` n /= 0 instead.

Your function, when read in English, would sound like: "any x in ns, where x does not equal n times x, for some input n". Aside from n = 1, this will always be true, and so no elements will be removed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM