榆树我需要空白,但是看起来像是一个新的宣言

时间:2016-02-05 22:41:51

标签: elm

我刚开始尝试榆树,而且我遇到了一个基本问题。

这是我的代码:

add : Int -> Int -> Int
add x y =
  x + y

add 3 4

我尝试在elm reactor的浏览器中运行它,但我遇到了这个问题。

Detected errors in 1 module.
-- SYNTAX PROBLEM ---------------------------------------------------- hello.elm

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:


I am looking for one of the following things:

    whitespace

我搜索文档但我在代码中找不到错误

编辑:如果删除add 3 4

,我没有任何错误

1 个答案:

答案 0 :(得分:4)

要在浏览器中运行此功能,您需要main方法,其类型为Graphics.ElementHtml.HtmlSignal Graphics.ElementSignal Html.Html。最简单的方法就是使用Graphics.Element.show,将“show”作为字符串。

import Graphics.Element exposing (show)

add : Int -> Int -> Int
add x y =
  x + y

main = show (add 3 4)

如果你只是想在没有制作可运行的Elm模块的情况下尝试代码,你也可以使用repl

:~ % elm repl
---- elm repl 0.16.0 -----------------------------------------------------------
 :help for help, :exit to exit, more at <https://github.com/elm-lang/elm-repl>
--------------------------------------------------------------------------------
> add x y = x + y
<function> : number -> number -> number
> add 3 4
7 : number
>