Support Infix functions and user defined operators #64
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In Erlang, we apply functions using prefix notation - name is followed by its arguments in brackets
plus(1, 2)
. Humans are more used to infix operators than prefix or postfix. If a function takes two arguments, we have the option of using it in infix form, where we place it between its first and second arguments1 /plus/ 2
.Operators
The
parse_transform
feature implements a syntax sugar for infix, which is compiled into valid Erlang code using corresponding function at compile-time. To apply a function using infix notation, we enclose its name in slash characters (/). This allows us to use any arity 2 functions as infix operators.Infix notation does not change a function's behavior, it is purely a syntactic convenience that help readability in a specific situation.
Example of math operator for tuples
User defined operators do not/cloud not/will not introduce any kind of polymorphism or overloading that Erlang does not already implement.
Partial application
The infix notation supports a partial application, just replace left/right operand with unbound variable _