条件句:Elm中多行if语句的语法如何?

Jon*_*Jon 4 elm

我正在阅读" 七周七种语言 "一书中的榆树章节.在第43页上,作者if通过以下方式描述了一条多行:

x = 5

if | x < 0 -> "too small" \
   | x > 0 -> "too big" \
   | otherwise -> "just right"
Run Code Online (Sandbox Code Playgroud)

然而,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
Run Code Online (Sandbox Code Playgroud)
  • 多行if语句的语法如何?

在文档(http://elm-lang.org/docs/syntax)我发现嵌套的使用if- else报表.是否可以创建书中描述的多行语句?

Cha*_*ert 10

if在Elm 0.16中删除了多向语法.这是讨论变化博客文章.

您可以使用else ifelse实现您所需的功能.

if x < 0 then
    "too small"
else if x > 0 then
    "too big"
else
    "just right
Run Code Online (Sandbox Code Playgroud)