Return 函数列表的元组

Return tuple of lists from function

我想在 Elm 中编写一个 returns 两个列表的函数,但我 运行 遇到了问题。似乎编译器无法匹配空列表的类型[]

import Html exposing (text)

main =
  let
    (a, b) = genList
  in
    text "Hello"


genList: List Float List Float
genList =
  ([], [])

编译错误如下:

Detected errors in 1 module.


-- TYPE MISMATCH ---------------------------------------------------------------

`genList` is being used in an unexpected way.

6|     (a, b) = genList
                ^^^^^^^
Based on its definition, `genList` has this type:

    List Float List Float

But you are trying to use it as:

    ( a, b )


-- TYPE MISMATCH ---------------------------------------------------------------

The definition of `genList` does not match its type annotation.

11| genList: List Float List Float
12| genList =
13|   ([], [])

The type annotation for `genList` says it is a:

    List Float List Float

But the definition (shown above) is a:

    ( List a, List b )

我还没有找到任何方法来为空列表提供类型提示。检查文档,它并没有那么深: https://guide.elm-lang.org/core_language.html http://elm-lang.org/docs/syntax#functions

类型签名还需要 (.., ..) 元组语法,如:

genList: (List Float, List Float)
genList =
  ([], [])

[] 是生成空列表的正确语法。如果您想了解更多关于 List 类型的信息,最好查看 package.elm-lang.org 上的文档。您分享的两个链接 "intro guides" 比综合文档还多。