gpt4 book ai didi

compiler-errors - Elm找不到Elm空白错误

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

我不断收到空白编译器错误,但找不到错误。
这是错误

I need whitespace, but got stuck on what looks like a new declaration. You are either missing some stuff in the declaration above or just need to add some spaces here:

41| view : Model -> Html -> Msg ^ I am looking for one of the following things:

whitespace


这是代码
view : Model -> Html -> Msg
view model =
div [] [
h2 [] [text ("Counter: " ++ (toString model))]
, button [type_ "button", onClick Add ] [text "add"]
, button [type_ "button", onClick Sub ] [text "subtract"]
, button [type_ "button", onClick Reset ] [text "reset"]
]

我必须错过一些非常简单的东西,但是我找不到它。

最佳答案

函数调用后需要一些空格。喜欢

x =
0

不会编译,但是
x =
0

会编译,这样说。您需要像这样缩进div []
view : Model -> Html -> Msg
view model =
div []
[ h2 [] [ text ("Counter: " ++ (toString model)) ]
, button [ type_ "button", onClick Add ] [ text "add" ]
, button [ type_ "button", onClick Sub ] [ text "subtract" ]
, button [ type_ "button", onClick Reset ] [ text "reset" ]
]

另外, View 的类型注释已关闭,当前您拥有
view : Model -> Html -> Msg

但这应该是
view : Model -> Html Msg

只是学习时的提示,您可以省略类型别名
--view : Model -> Html Msg
view model =

很好,您可以在以后对语言更熟悉时添加注释,这就是我的学习方法。

有关工作版本的链接,请参见 here

关于compiler-errors - Elm找不到Elm空白错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49671711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com