question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

unify operator overloading

See original GitHub issue

a syntax like:

operator def (a: Int) + (b: Int) -> Int:
  ...

could allow us to unify unary and binary operators. We might not want many operators which have not been popular in most programming languages. That said, it is ugly to have some exceptions to rules and it makes things harder to learn.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:23 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
johnynekcommented, Mar 25, 2019

so my new proposal is that operator ++ is exactly like concat for instance. It can appear anywhere a binding name can:

operator ++ = foo
[1] ++ [2]

def takeOp(operator /, baz, bar):
  baz / bar

match x:
   operator f: f(1)

etc…

So, operator is a key word that allows us using operator names as binds.

Then next part is that an operator without that prefix f + is parsed as Apply(Operator("+"), f).

The last part is that we will limit operators to avoid : _ , @ ( ) and . so we don’t have any ambiguity with other existing symbols.

I think with #192 it should be pretty easy to implement this (although doing that refactor was a brutal several hours…)

1reaction
johnynekcommented, Mar 24, 2019

-x could just be 0-x or neg(x) or x.neg

Simplicity and consistency are major goals here. That will inevitably leave some verbose corners.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chapter 14 Overloaded Operators
Chapter 14 Overloaded Operators. A Modelica operator record can define the behavior for operations such as constructing, adding, multiplying etc.
Read more >
Rules for Overloading and Overload Operators
There are ten rules for overloading and overload operators in the C++ core guidelines. Many of them are quite obvious, but your software...
Read more >
Operator Overloading - C++ Fundamentals for Professionals
We can overload the assignment operator by implementing it as a copy or move assignment operator. It has to be implemented in a...
Read more >
Unification (computer science)
In logic and computer science, unification is an algorithmic process of solving equations between symbolic expressions. Depending on which expressions (also ...
Read more >
Chapter 10: Operator Overloading
When used correctly, operator overloading can lead to intuitive, template-friendly code that elegantly performs complex operations behind the scenes. However,.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found