【发布时间】:2013-10-05 09:20:45
【问题描述】:
我正在编写此代码,我需要取消对函数进行归类,以便它允许元组值输入。这是我的代码:
printField :: Int -> String -> String
--the function to be uncurried
printRow :: [(Int, String)] -> String
printRow d = map (uncurry printField) d
但它向我抛出了以下错误,我不知道为什么:
Couldn't match type '[Char]' with 'Char' Expected type: Int -> String -> Char Actual type: Int -> String -> String In the first argument of 'uncurry', namely 'printField' In the first argument of 'map', namely '<uncurry printField>' In the expression: map <uncurry printField> d
有谁知道这意味着什么以及如何解决它?
提前致谢!
最好的问候, Skyfe。
【问题讨论】:
-
地图类型为
map :: (a -> b) -> [a] -> [b]。所以 printRows 应该返回 [String] 而不是 String。还是您打算使用 concatMap ? -
啊,没错!完全忘了连接它,谢谢。