Compiler errors Elm错误:我正在寻找以下内容之一:“'&引用;

Compiler errors Elm错误:我正在寻找以下内容之一:“'&引用;,compiler-errors,elm,Compiler Errors,Elm,我得到一个编译错误: 我正在寻找以下内容之一: "'" "." a pattern an equals sign '=' more letters in this name whitespace 它是一个不完整的类型还是功能不好?首字母大写?我已经尝试过逐块构建文件,但在添加方法后仍然会出现错误。如果删除函数类型注释,则函数定义会出错。我显然误解了一个基本概念 module Test exposing (Test, TestRoot, TestId, GetContainedTes

我得到一个编译错误:

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

 "'"
 "."
 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

注意:我不是在请求有关该函数的帮助(尽管我很欢迎)。我试图克服编译器错误,您提到的具体错误是因为您试图使用大写字母作为函数的第一个字符
GetContainedTests
。在Elm中,所有函数必须以小写字母开头。只有类型、类型别名、类型构造函数和模块名称可以(必须)以大写字母开头

您还可能会遇到一些编译错误:

  • List.map
    中的第一个参数应该用括号括起来,而不是大括号
  • 您将在定义递归类型别名时遇到编译错误。这是因为您的
    测试
    别名引用自身。有关问题所在的更多信息,您可以。编译器还建议将
    Test
    设置为类型而不是别名,如下所示:

    型式试验
    =测试
    {id:TestId
    ,集装箱运输:TestId
    ,标题:字符串
    ,儿童:列表测试
    }
    
    我想导出(公开)该函数。如果没有大写字母,这是否违反协议?如果大小写正确,您可以按照您在顶部定义的方式公开函数:
    模块测试公开(Test、TestRoot、TestId、getContainedTests)
    。也许你把它和只输出大写名称的
    Go
    语言混淆了?我最近也写了很多Go,在考虑输出什么时,我总是要反复考虑