Elm: unexpected '|', expecting whitespace or end of input

I recently bought "Seven more languages in seven weeks" (E-Book). I really love the "Seven .. in seven weeks" series - it's intense + challenging + mind-bending.

However, one of the things that was driving me crazy was that this simple piece of Elm code:


type Color = Black | White

generated this error:

unexpected '|'
expecting whitespace or end of input

After trying out various things, the solution turned out to be quite simple - change your Terminal settings to use ASCII instead of Unicode-8, and everything works as expected (you might want to ensure your editor of choice also uses ASCII encoding if you're not using the REPL).

Happy coding!

UPDATE
Turns out the solution wasn't related to the character encoding - it seems to be a bug in the ELM REPL where it doesn't recover once you've typed in something wrong:

franks-air:~ frank$ elm-repl

Elm REPL 0.4 <https: elm-lang="" elm-repl="" github.com=""></https:>
Type :help for help, :exit to exit
> data List = Empty | Node Int List

Error in repl-temp-000.elm:

Parse error at (line 2, column 19):
unexpected '|'
expecting whitespace or end of input


> type List = Empty | Node Int List

Error in repl-temp-000.elm:

Parse error at (line 3, column 19):
unexpected '|'
expecting whitespace or end of input


franks-air:~ frank$ elm-repl
Elm REPL 0.4 <https: elm-lang="" elm-repl="" github.com=""></https:>
Type :help for help, :exit to exit

> type List = Empty | Node Int List
>


597 Words

2015-03-01T14:20:00-08:00