这个问题与这个Function Composition VS Function Application有关,由antal s-z回答。Haskell类型错误从函数应用到函数组合
你如何得到这个?
map has type (a -> b) -> [a] -> [b]
head has type [a] -> a
map head has type [[a]] -> [a]
为什么下面的代码有函数组合的类型错误?
test :: [Char] -> Bool
test xs = not . null xs
getMiddleInitials :: [String] -> [Char]
getMiddleInitials middleNames = map head . filter (\mn -> not . null mn) middleNames
,但这并没有错误类型
getFirstElements :: [[a]] -> [a]
getFirstElements = map head . filter (not . null)
它是一个必须以利用函数组合写点免费功能? 我还是不太了解函数组合的用法。
请帮忙。 谢谢。
真的不明白rejectMapping例子的最后部分。 – peterwkc 2010-06-27 03:07:07
哪部分你不明白?它背后的动机,它应该做什么,或者它是如何工作的?它只使用你已经看过的东西,所以如果你仔细想想,你应该可以遵循它! – 2010-06-27 03:28:51