【发布时间】:2013-09-25 12:52:58
【问题描述】:
我想从列表中删除一些元素。到目前为止,我有一个删除功能:
deleteElem :: Int -> [a] -> [a]
deleteElem _ [] = []
deleteElem x zs | x > 0 = take (x-1) zs ++ drop x zs
| otherwise = zs
例如,我想删除两个位置,它们存储在元素列表中的列表中。 所以这很好用:
map (deleteElem 2) [["hello", "whatever", "foo", "bar"], ["hello", "whatever", "foo", "bar"], ["hello", "whatever", "foo", "bar"], [hello", "whatever", "foo", "bar"]]
我会得到结果的:
[["hello", "whatever", "bar"], ["hello", "whatever", "bar"], ["hello", "whatever", "bar"], [hello", "whatever", "bar"]]
但现在我想申请deleteElem [2,3]
【问题讨论】:
-
以 deleteElem 作为运算符的双重映射。但这也不起作用
标签: list haskell dictionary