考虑清单
[[],[1],[1,2],[1,2,3],[],[2],[2,3],[],[3],[]]
我想过滤掉所有不是空列表的元素,即过滤后的输出应该给我这样的结果:
[[1],[1,2],[1,2,3],[2],[2,3],[3]]
以下代码失败:
myfilter lst = filter(\x -> x/=[]) lst
[12,3,[]] 出现以下错误
No instance for (Num [a])
arising from the literal `3' at <interactive>:1:13
Possible fix: add an instance declaration for (Num [a])
In the expression: 3
In the first argument of `myfilter', namely `[12, 3, []]'
In the expression: myfilter [12, 3, []]