2017-06-21 7 views
1

Elmに2つのリストを返す関数を書いてみたいが、私は問題にぶつかっている。コンパイラが空のリスト[]のタイプと一致できないようです。次のように関数のリストのタプルを返す

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

答えて

3

型シグネチャも同様(.., ..)タプル構文を必要とする:

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

[]はしかし、空のリストを生成するための正しい構文です。 Listタイプの詳細については、package.elm-lang.orgのドキュメントをご覧ください。あなたが共有した2つのリンクは包括的なドキュメントよりも "イントロガイド"です。

関連する問題