You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a set of traits corresponding to various operators in the language (e.g. Add, Sub, Index), and rewrite operator support in the compiler to delegate to methods of these traits. This would also allow users to implement operator support for custom types by implementing the operator traits.
The exact design of these traits depends on how powerful the trait system is by that point, but here is an idea of how they could look like:
trait Add<T> {
fun add(self, rhs: T): T;
}
struct MyNumber : Add<MyNumber> {
// ...
fun add(self, rhs: MyNumber): MyNumber {
// ...
}
}
fun main() {
var x: MyNumber, y: MyNumber;
// Expands to x.add(y).
var z = x + y;
// Causes an error that clearly states that `bool` does not implement `Add<bool>`.
var b = true + false;
}
The text was updated successfully, but these errors were encountered:
Add a set of traits corresponding to various operators in the language (e.g.
Add
,Sub
,Index
), and rewrite operator support in the compiler to delegate to methods of these traits. This would also allow users to implement operator support for custom types by implementing the operator traits.The exact design of these traits depends on how powerful the trait system is by that point, but here is an idea of how they could look like:
The text was updated successfully, but these errors were encountered: