榆树错误:我正在寻找以下其中一项:“'”

时间:2016-12-18 23:49:56

标签: compiler-errors elm

我收到编译错误:

我正在寻找以下其中一项:

 "'"
 "."
 a pattern
 an equals sign '='
 more letters in this name
 whitespace

是不完整的类型还是功能不好?首字母大写?我尝试逐块构建文件,一旦添加方法,我仍然会收到错误。如果我删除函数类型注释,我会在函数定义中出错。我明显误解了一个基本概念

module Test exposing (Test, TestRoot, TestId, GetContainedTests)

type  TestId = String

type alias Test =
    { id : TestId
    , containerId : TestId
    , title : String
    , children : List Test
    }    

type alias TestRoot =
    { id : TestId
    , title : String
    , children : List Test
}   

GetContainedTests: Test -> List Test                    -- error here I am looking for one of the following things: "'"     "."     a pattern     an equals sign '='     more letters in this name     whitespace
GetContainedTests item = 
    let
        result : List Test
        result = item.children
            -- if I comment out the GetContainedTests type annotation, I get an error on the ".map" below: I am looking for one of the following things:     an upper case name

        List.map {\childItem -> List.append result GetContainedTests childItem} item.children
    in
        result

注意:我不是要求帮助这个功能(虽然我欢迎它)。我正试图超越编译器错误

1 个答案:

答案 0 :(得分:3)

您提到的具体错误是因为您尝试使用大写字母作为函数//initialize a global var to control the callback state var callbackCount = 0; //call the function that has a callback someObj.executeCallback(function () { callbackCount++; runOtherCode(); }); someObj2.executeCallback(function () { callbackCount++; runOtherCode(); }); //call function that has to wait continueExec(); function continueExec() { //here is the trick, wait until var callbackCount is set number of callback functions if (callbackCount < 2) { setTimeout(continueExec, 1000); return; } //Finally, do what you need doSomeThing(); } 的第一个字符。在Elm中,所有函数必须以小写字母开头。只有类型,类型别名,类型构造函数和模块名称可以(必须)以大写字母开头。

您可能会遇到的其他一些编译错误:

  1. GetContainedTests中的第一个参数应括在括号中,而不是大括号。
  2. 您将收到有关定义递归类型别名的编译错误。这是因为您的List.map别名引用了自己。有关问题的详细信息,您可以read up on the information in the link provided in the error message。编译器还建议将Test设为类型而不是别名,如下所示:

    Test