1
我想写一个函数,返回Elm中的两个列表,但我遇到了问题。看起来编译器不能匹配空列表[]
的类型。从函数返回列表的元组
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