compiler-errors - 榆树错误 : I am looking for one of the following things: "' "

标签 compiler-errors elm

我收到编译错误:

我正在寻找以下内容之一:

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

它是不完整的类型还是功能不好?首字母大写?我已经尝试逐 block 构建文件,但添加方法后仍然会收到错误消息。如果我删除函数类型注释,函数定义会出错。我显然在这里误解了一个基本概念
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

注意:我不是在寻求有关该功能的帮助(尽管我欢迎它)。我正在尝试克服编译器错误

最佳答案

您提到的具体错误是因为您试图使用大写字母作为函数的第一个字符 GetContainedTests .在 Elm 中,所有函数都必须以小写字母开头。只有类型、类型别名、类型构造函数和模块名称可以(必须)以大写字母开头。

其他一些你会得到编译错误的事情:

  • List.map 中的第一个参数应该用括号括起来,而不是花括号。

  • 您将收到有关定义递归类型别名的编译错误。这是因为您的 Test别名引用自身。有关问题所在的更多信息,您可以 read up on the information in the link provided in the error message .编译器还建议制作 Test类型而不是别名,如下所示:

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

    关于compiler-errors - 榆树错误 : I am looking for one of the following things: "' ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41214131/

    相关文章:

    java - 遇到时间错误(Java)

    elm - Elm 中如何自动将 CSRF Token 转换为 HTTP 请求头?

    html - 为什么 Elm 不提供 HTML 文档头标签?

    json - 如何在Elm中提取Http请求的结果

    elm - 在列表中的类型变体上创建条件

    c++ - Visual Studio 2015 C++项目错误C++ 11标准

    scala - Scala : compilation error: not found type

    java - 如何在命令行中为 Tomcat 编译 servlet?错误 : package javax. servlet 不存在

    GoLand IDE 无法正确编译。如何设置正确的路径?

    keyboard - 如何将键盘按下与操作联系起来