haskell从列表列表中删除所有出现的给定值

时间:2012-04-07 01:33:17

标签: haskell

我想从列表列表中删除所有出现的给定值。例如, 输入:

'a' ["abc", "bc", "aa"] 

输出:

 ["bc", "bc", ""]

到目前为止:

remove :: Eq a => a -> [[a ]] -> [[a ]]
remove y xs = filter(\x -> x/= y) xs

我收到了错误,请提前谢谢。

1 个答案:

答案 0 :(得分:10)

您需要映射外部列表。

remove y xs = map (filter(\x -> x/= y)) xs

这里你实际上并不需要lambda,更好:

remove y xs = map (filter(/=y)) xs