【问题标题】:Uncurrying function for tupel input returns errortupel 输入的 uncurrying 函数返回错误
【发布时间】: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 -&gt; b) -&gt; [a] -&gt; [b]。所以 printRows 应该返回 [String] 而不是 String。还是您打算使用 concatMap ?
  • 啊,没错!完全忘了连接它,谢谢。

标签: haskell map tuples


【解决方案1】:

正如 Satvik 已经提到的,使用 concatMap

您可以在此处使用 eta 缩减并删除多余的 d

printRow = concatMap (uncurry printField)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-03
    • 2020-08-09
    • 1970-01-01
    • 2015-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多