Closed elijahdorman closed 6 years ago
skinny arrows have precedent, but in all languages I looked that used ->
, their functions also used ->
.
So, while intuitively the fat arrow in both places seems to create an ambiguity, this has not been a problem for existing languages. Can you provide examples of this being a problem for, say, Erlang?
You can get away with a lot when your syntax is already quite simple. Statements being expressions also helps. Case and function equivalency helps. Consistent function declaration syntax helps too.
JS doesn't have these things. Function syntax takes a few forms (statement, function literal, fat arrow, fat arrow without parens). The JS syntax is more complicated. Statements aren't always expressions.
Most importantly, there isn't a proposal for multi-arity (or type) function pattern matching. Equivalency between cases and functions isn't on the table, so they are fundamentally different.
Elixir uses skinny arrow (->
) for case statements.
https://elixirschool.com/en/lessons/basics/control-structures/#case
And uses the reverse (<-
) for pattern matching in for loops:
https://elixir-lang.org/getting-started/comprehensions.html#generators-and-filters
And for pattern matches in with statements:
https://elixirschool.com/en/lessons/basics/control-structures/#with
@mgwidmann That's because Elixir uses skinny arrow for functions: https://elixirschool.com/en/lessons/basics/functions/#anonymous-functions
@elijahdorman Erlang syntax is not something I'd label as "simple". Ditto Elixir. Ditto most "FP" languages not in the Lisp family (see also the syntax soup that is Haskell).
Heck, I consider JS' syntax more straightforward than most of these.
Closing this because the new proposal uses ~>
. I assume this syntax will change eventually, but it resolves this issue for now :)
Fat arrow overloading makes distinguishing between functions and patterns a little ambiguous. Skinny arrow is not the greatest answer, but still provides more visual indication.