Should literal list patterns allow multiline?
There's currently no way to write this:
case [ maybeFoo, maybeBar, maybeBaz ] of
[ Just foo
, Just bar
, Just baz
] ->
The list pattern match gets reformatted into a single line no matter what:
case [ maybeFoo, maybeBar, maybeBaz ] of
[ Just foo, Just bar, Just baz ] ->
I ran into this when working on an API where it makes sense to pattern match on list literals, and was pretty surprised to realize it was impossible to write them the first way! 😅
This may also apply to tuples and records, come to think of it.
I ran into this today when trying to write a function that determines the state of a TicTacToe board, in exactly the way you imagine the naïve implementation of that function would look. It presented itself as a syntax error from improper indentation, and I'm not sure the junior I was mentoring would have caught that on her own.
Could someone provide some of the real-world code where they needed a case statement like this?
Implementing this would require also allowing this for top-level definitions, and in lambas (which probably wouldn't use literal list patterns, but the same would apply for tuples). Also note that in
case [ maybeFoo, maybeBar, maybeBaz ] of
[ Just foo
, Just bar
, Just baz
] ->
elm-compiler doesn't actually allow that unless the , and ] -> lines are indented at least one more space, so we'd also have to define what the formatting would look like here.