条件:Elm 中多行 if 语句的语法如何?
Conditionals: How is the syntax for a multiline if statement in Elm?
我正在阅读 七周学会更多语言 一书的 Elm 章节。
在第 43 页上,作者用以下方式描述了多行 if
:
x = 5
if | x < 0 -> "too small" \
| x > 0 -> "too big" \
| otherwise -> "just right"
但是,Elm-REPL 抱怨 SYNTAX PROBLEM
:
> if | x < 0 -> "too small" \
| | x > 0 -> "too big" \
| | otherwise -> "just right"
-- SYNTAX PROBLEM -------------------------------------------- repl-temp-000.elm
I ran into something unexpected when parsing your code!
3| if | x < 0 -> "too small"
^
I am looking for one of the following things:
an expression
whitespace
- 多行 if 语句的语法如何?
在文档中 (http://elm-lang.org/docs/syntax) 我找到了用法
嵌套 if
-else
语句。是否可以创建多行语句,例如
书中有描述吗?
Elm 0.16 中删除了多路 if
语法。这是 blog post discussing the change.
您可以使用 else if
和 else
来实现您想要的功能。
if x < 0 then
"too small"
else if x > 0 then
"too big"
else
"just right
我正在阅读 七周学会更多语言 一书的 Elm 章节。
在第 43 页上,作者用以下方式描述了多行 if
:
x = 5
if | x < 0 -> "too small" \
| x > 0 -> "too big" \
| otherwise -> "just right"
但是,Elm-REPL 抱怨 SYNTAX PROBLEM
:
> if | x < 0 -> "too small" \
| | x > 0 -> "too big" \
| | otherwise -> "just right"
-- SYNTAX PROBLEM -------------------------------------------- repl-temp-000.elm
I ran into something unexpected when parsing your code!
3| if | x < 0 -> "too small"
^
I am looking for one of the following things:
an expression
whitespace
- 多行 if 语句的语法如何?
在文档中 (http://elm-lang.org/docs/syntax) 我找到了用法
嵌套 if
-else
语句。是否可以创建多行语句,例如
书中有描述吗?
Elm 0.16 中删除了多路 if
语法。这是 blog post discussing the change.
您可以使用 else if
和 else
来实现您想要的功能。
if x < 0 then
"too small"
else if x > 0 then
"too big"
else
"just right