【问题标题】:HASKELL: Add the first x element of a list of lists in an other [closed]HASKELL:将列表列表的第一个 x 元素添加到另一个 [关闭]
【发布时间】:2020-04-27 14:07:54
【问题描述】:

我是 haskell 的新手,我想创建一个函数来获取列表列表的第 x 个元素并返回它。

示例:[[14, 15, 84], [84, 79, 78], [45, 78, 98], [45, 48, 98]] 我只想要第 2 个所以我的函数需要返回 : [[14, 15, 84], [84, 79, 78]]

push :: [a] -> [[a]] -> [[a]]
push = (:)

generateKluster :: Int -> Int -> [[Int]] -> [[Int]] -> [[Int]] 
generateKluster nb_return count (a:as) b
  | nb_return == count = b
  | nb_return < count = (generateKluster x (y + 1) as (push a b))

我收到了这个错误信息

*Main> 3 0 [[12, 45, 52], [14, 15, 65], [15, 46, 48], [45, 78, 98], [45, 65, 45]] [[]]

<interactive>:1:1: error:
    • Non type-variable argument
        in the constraint: Num (t1 -> [[a1]] -> [[a2]] -> t2)
      (Use FlexibleContexts to permit this)
    • When checking the inferred type
        it :: forall t1 a1 a2 t2.
              (Num (t1 -> [[a1]] -> [[a2]] -> t2), Num a1, Num t1) =>
              t2

【问题讨论】:

    标签: list haskell compiler-errors


    【解决方案1】:

    您需要在 GHCi 中调用 generateKluster。 喜欢:generateKluster 3 0 [[12, 45, 52], [14, 15, 65], [15, 46, 48], [45, 78, 98], [45, 65, 45]] [[]]

    【讨论】:

      猜你喜欢
      • 2018-09-03
      • 2013-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      相关资源
      最近更新 更多