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
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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With