ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:44:25 24 4
gpt4 key购买 nike

我收到编译错误:

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

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

    24 4 0
    文章推荐: xcode - CoreData NSManagedSubClass文件生成重复文件?
    文章推荐: android - 在我们的 PWA 中触发 JavaScript 错误的这个未知的源自 Google 的客户端是什么?
    文章推荐: compiler-errors - Elm类型列表和类型别名-获取提取的列表以识别类型
    文章推荐: compiler-errors - 如何摆脱属性网格警告?
    行者123
    个人简介

    我是一名优秀的程序员,十分优秀!

    滴滴打车优惠券免费领取
    滴滴打车优惠券
    全站热门文章
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com