> On Mar 14, 2019, at 11:56 AM, Unified Front <
unif...@gmail.com> wrote:
>
> ... Simplification like this pays off in the long run ...
Other responses have addressed various aspects of your proposal, including:
- maintaining stability in this version of Elixir
- ways to get the proposed behavior using a macro
- desire for a research-backed proposal rationale
- keeping Dialyzer distinct from the base language
However, I haven't seen any comments on the merits of your proposed syntax. So,
because it touches on some issues of concern to me, I'll give it a try...
You use the word "simplification". As Inigo Montoya said in "The Princess Bride",
"I do not think it means what you think it means." Borrowing some language from
Rich Hickey, I'd say that your proposal "complects" @spec and def. That is, it
jams their concerns into a single syntactic mashup. Rather than simplifying the
language's syntax, this would make it even more complicated.
The @def and @spec syntax are already rather complicated, because each has to deal
with a substantial number of concerns. For example, @def has to handle:
- naming of functions and parameters
- pattern matching and dispatching
- argument binding and destructuring
- default values and keyword lists
- guard clauses
I realize that folding type information into function headers is a common approach
in other languages, but I think Elixir's approach keeps the syntax simpler and the
conceptual load lighter. Indeed, I'd like to make the header syntax even simpler.
For example, defguard/1 (
https://hexdocs.pm/elixir/Kernel.html#defguard/1) already
lets us extract complicated guard expressions from the function header. However,
I don't know of any equivalent way to extract complex pattern matching expressions
(and defining one is far above my pay grade :-).
Although some might argue that simplicity and complexity are matters of taste, I'd
assert that keeping things simpler (in Hickey's sense) makes them easier for humans
to deal with. When I read a bit of code, my brain has to act a bit like a compiler;
simpler syntax (and logic) give it fewer things that it has to keep on the stack...
-r