Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditionals: How is the syntax for a multiline if statement in Elm?

Tags:

elm

I am reading the Elm chapter of the book Seven More Languages in Seven Weeks. On page 43 the author describes a multi line if in the following way:

x = 5

if | x < 0 -> "too small" \
   | x > 0 -> "too big" \
   | otherwise -> "just right"

However, the Elm-REPL complains about a 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
  • How is the syntax for a multiline if statement?

In the documentation (http://elm-lang.org/docs/syntax) I found the usage of nested if-else statements. Is it possible to create multiline statements like described in the book?

like image 776
Jon Avatar asked Dec 24 '22 22:12

Jon


1 Answers

The multi-way if syntax was removed in Elm 0.16. Here is the blog post discussing the change.

You can use else if and else to achieve the functionality you are after.

if x < 0 then
    "too small"
else if x > 0 then
    "too big"
else
    "just right
like image 62
Chad Gilbert Avatar answered May 23 '23 07:05

Chad Gilbert