【发布时间】:2017-10-22 19:04:16
【问题描述】:
有没有办法使用列表理解来编写 Haskell 过滤器函数的实现?
一个错误不断出现,我不知道如何处理它。这就是我所拥有的:
filter' :: (a -> Bool) -> [a] -> [a]
filter' _ [] = []
filter' f xs = [f x | x <- xs]
任何指导或链接将不胜感激。
【问题讨论】:
-
对 Haskell 中列表理解的概述:wiki.haskell.org/List_comprehension
-
你真的应该多花点精力自己解决这些问题。看起来您所做的只是从the
mapimplementation that was given to you in your last question 复制解决方案。以后,请详细说明您为什么会感到困惑的思考过程,以便人们可以更好地帮助您。
标签: list haskell filter functional-programming list-comprehension