创建一个toLists函数

时间:2019-04-12 23:43:24

标签: haskell

我正在尝试修改更大的脚本---作为此过程的一部分,我正在尝试将toPairs的功能更改为toLists:

toPairs :: TypeRepMap f -> [(SomeTypeRep, WrapTypeable f)]
toPairs = map toPair . toTriples
  where
  toPair :: (a, Any, Any) -> (SomeTypeRep, WrapTypeable f)
  toPair (_, v, k) =
    ( SomeTypeRep (anyToTypeRep k)
    , wrapTypeable (anyToTypeRep k) (fromAny v)
    )

toLists :: TypeRepMap f -> [SomeTypeRep]
toLists = toList . toTriples
  where
  toList :: (a, Any, Any) -> [SomeTypeRep]
  toList (_, v, k) = SomeTypeRep (anyToTypeRep k)

但是尝试编译时出现此错误:

    • Couldn't match expected type ‘[SomeTypeRep]’
                  with actual type ‘SomeTypeRep’
    • In the expression: SomeTypeRep (anyToTypeRep k)
      In an equation for ‘toList’:
          toList (_, v, k) = SomeTypeRep (anyToTypeRep k)
      In an equation for ‘toLists’:
          toLists
            = toList . toTriples
            where
                toList :: (a, Any, Any) -> [SomeTypeRep]
                toList (_, v, k) = SomeTypeRep (anyToTypeRep k)
    |
108 |   toList (_, v, k) = SomeTypeRep (anyToTypeRep k)
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

我还尝试将最后一行更改为toList (_, v, k) = [SomeTypeRep] ---但随后它说SomeTypeRep应用于的参数太少。

作为参考,这是我要尝试的:https://github.com/kowainik/typerep-map/issues/69

我是Haskell的超级新手,完全迷路了。如何创建仅生成列表的函数?而不是元组列表?

0 个答案:

没有答案