Elm error: I am looking for one of the following things: "'"
Elm error: I am looking for one of the following things: "'"
我遇到编译错误:
我正在寻找以下内容之一:
"'"
"."
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
别名引用了它自己。有关问题是什么的更多信息,您可以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
}
我遇到编译错误:
我正在寻找以下内容之一:
"'"
"."
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
别名引用了它自己。有关问题是什么的更多信息,您可以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
}