0 -> "too big-6ren">
gpt4 book ai didi

elm - 条件 : How is the syntax for a multiline if statement in Elm?

转载 作者:行者123 更新时间:2023-12-04 18:41:37 24 4
gpt4 key购买 nike

我正在阅读《七周内增加七种语言》一书的榆树章节。
作者在第 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声明。是否可以创建多行语句,例如
    书上描述的?

    最佳答案

    多路if Elm 0.16 中删除了语法。这是blog post discussing the change .

    您可以使用 else ifelse实现您所追求的功能。

    if x < 0 then
    "too small"
    else if x > 0 then
    "too big"
    else
    "just right

    关于elm - 条件 : How is the syntax for a multiline if statement in Elm?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41401074/

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