将“map f (map g xs)”写入您可以编写的对 map 的单个调用
example xs = map (f.g) xs
但是您如何将“filter p (filter q xs)”编写为对过滤器的单个调用?点运算符似乎不适用于过滤器,因为它适用于 map 。猜测您会使用其他东西作为谓词?
最佳答案
如果您定义了一个如下所示的函数 both
:
both :: (a -> Bool) -> (a -> Bool) -> a -> Bool
both f g x = f x && g x
然后你可以写:
example xs = filter (both p q) xs
我不确定是否有一个标准函数可以为您执行此操作...
关于haskell,链接过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1712031/