【发布时间】:2019-12-14 08:29:06
【问题描述】:
函数定义已经给出
filterMany :: [a -> Bool] -> [a] -> [a]
filterMany (f:fs) [] = []
filterMany (f:fs) (x)
| filter (f) x == True = x : filter (fs) x
| otherwise = filter (fs) x
输出应该是:
filterMany [even, odd] [1..10] == []
filterMany [even, (\x -> x `mod` 4 /= 0)] [1..10] == [2,6,10]
filterMany [(<7), (>3), odd] [1..20] == [5]
【问题讨论】:
-
这能回答你的问题吗? How do you combine filter conditions
-
您应该递归调用
filterMany,而不是filter。删除== True,它是多余的。(variable)中的括号也是多余的。 -
你的意思是:filterMany' (f:fs) [] = [] filterMany' (f:fs) x | f x = x : filterMany' fs x |否则 = filterMany' fs x
标签: haskell