tl;dr write union types with a | before each case, like so:
type Maybe a =
| Just a
| Nothing
The current syntax for defining union types has these problems:
= at the end of the line instead of the beginning of the following lineDo what F# does: require that each tag be on a different line, and preceded by a |.
From evancz/elm-todomvc
type Msg
= NoOp
| UpdateField String
| EditingTask Int Bool
| UpdateTask Int String
| Add
| Delete Int
| DeleteComplete
| Check Int Bool
| CheckAll Bool
| ChangeVisibility String
becomes
type Msg =
| NoOp
| UpdateField String
| EditingTask Int Bool
| UpdateTask Int String
| Add
| Delete Int
| DeleteComplete
| Check Int Bool
| CheckAll Bool
| ChangeVisibility String
This is currently supported, but would no longer be.
type Bool = True | False
becomes
type Bool =
| True
| False
This is currently supported, but would no longer be.
type Maybe a = Just a
| Nothing
becomes
type Maybe a =
| Just a
| Nothing
As an aside, I don't think this is in any way urgent. I just think it's a good idea and wanted to document it.
What if the preceding bar was optional, not required? That would be a non-breaking syntax change.
I'd prefer that to status quo, since then I could write my stuff in the
nice way, so sure! :)
On Mon, May 16, 2016, 6:16 PM Max Goldstein [email protected]
wrote:
What if the preceding bar was optional, not required? That would be a
non-breaking syntax change.—
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
https://github.com/elm-lang/elm-compiler/issues/1385#issuecomment-219594216
Thanks. Added to #1375. In case any OCaml people ever see this, they did it first ;)
As a side note, with a single case union in F# the first bar is entirely optional:
So
type Msg = UpdateField of string
Is valid syntax rather than having to do:
type Msg =
| UpdateField of string
If single line unions are no longer allowed as proposed, why not just get rid of the | syntax altogether? Just use indentation as with case.
Maybe, leading bar could be made optional?
@Heimdell See my May 16th comment...
Most helpful comment
What if the preceding bar was optional, not required? That would be a non-breaking syntax change.