试图获得:
removeAll :: Int -> [Int] -> [Int]
removeAll a b = [ | a /= i = i | i <- b ]
工作但不断得到解析错误。我是否正确使用了警卫?
答案 0 :(得分:4)
正确的语法是:
removeAll a b = [ i | i <- b, a /= i ]
您也可以使用过滤器解决此问题:
removeAll a = filter (/= a)
答案 1 :(得分:1)
removeAll :: Int -> [Int] -> [Int]
removeAll a b = [ x | x <- b, x /= a ]