ProvableHQ / leo

🦁 The Leo Programming Language. A Programming Language for Formally Verified, Zero-Knowledge Applications
https://leo-lang.org/
GNU General Public License v3.0
4.79k stars 655 forks source link

[Proposal] Operator overloading #1467

Open acoglio opened 2 years ago

acoglio commented 2 years ago

💥 Proposal

This has been brought up in the past.

The idea is to allow symbolic prefix (unary) and infix (binary) operators to be overloaded on user-defined types, besides built-in types. So for example one could define a type for matrices and use + to add them.

Part of the motivation (also previously discussed) is to turn the group type and operations, currently built-in, into a library. There may be in fact different groups of interest that Leo code may want to manipulate, beyond the one that is currently supported. (This is orthogonal to support for different curves: given one curve, there may be multiple groups of interest, such as subgroups for different generators, as well as the group for the whole curve.) For library group operations, it would be nice to use the same operators used now for built-in group operations.

Centril commented 2 years ago

Haskell's approach to operator overloading is pretty good. We'd probably also want bounded polymorphism to handle this nicely.