我想根据其值过滤Data.map;更确切地说,映射键是(Int,Int)
,值是Int类型。
我想只保留密钥为> = 2
这是创建地图的功能:
countElems :: [(Int,Int)] -> M.Map (Int,Int) Int
countElems = M.fromListWith (+) . flip zip (repeat 1)
以下是过滤此地图的(错误)代码:
let elems = countElems $ take 10000 liste7
let elems2 = filter (\i -> i > 2) elems
putStrLn $ show elems2
错误发生在过滤行:
Couldn't match expected type `[a0]'
with actual type `M.Map (Int, Int) Int'
In the second argument of `filter', namely `elems'
In the expression: filter (\ i -> i > 2) elems
In an equation for `elems2': elems2 = filter (\ i -> i > 2) elems
我不明白这条错误信息。