The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

39590 (3) [Avatar] Offline
#1
if-expression does-not require indentation following new-lines, but functions do? Why?

> if 1 /= 2 then \
| "yay" \
| else \
| "nay"
"yay" : String


> f x = \
| x
-- SYNTAX PROBLEM -------------------------------------------- repl-temp-000.elm

The = operator is reserved for defining variables. Maybe you want == instead? Or
maybe you are defining a variable, but there is whitespace before it?

3|   f x = 
         ^
Maybe <http://elm-lang.org/docs/syntax> can help you figure it out.


> f x = \
|   x
<function> : a -> a
Danny G (3) [Avatar] Offline
#2
I'm not a huge fan of the title of this post BTW... but to your problem:

I was able to reproduce, but it looks like adding a space on the second line makes it work. I agree the error you posted is misleading.
> f x = \
|   x
<function> : a -> a



I'd also be careful in general when writing "long" functions and using the '\' symbol. It is often used for anonymous function definitions.
doubler = \x -> x * 2