Haskell相交(List)

时间:2012-12-20 07:31:48

标签: list haskell intersect

我试图得到两个列表相交的“对立面”: 像:

let all  = [1..5]
let mask = [2,3]
let res  = ???
-- let res = all `intersect` mask <-- reverse/opposite ?
-- I want to get [1,4,5] ?

1 个答案:

答案 0 :(得分:16)

您正在寻找设置差异,这是来自Data.List\\运算符:

Prelude> import Data.List ((\\))
Prelude Data.List> let all  = [1..5]
Prelude Data.List> let mask = [2,3]
Prelude Data.List> all \\ mask
[1,4,5]