-
Notifications
You must be signed in to change notification settings - Fork 265
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Title: friend and this for commutative operators.
Description:
This is a first write of an operator* in Cpp2:
quantity: @struct <Unit: type> type = {
number: i32;
operator*: (this, r: i32) -> quantity = (number * r);
}
operator*: <Unit> (l: i32, r: quantity<Unit>) -> quantity<Unit> = r * l;
The signatures are unfortunately too dissimilar and far apart.
We could remediate:
quantity: @struct <Unit: type> type = {
number: i32;
operator/: /* ... */;
operator%: /* ... */;
}
operator*: <Unit> (l: quantity<Unit>, r: i32) -> quantity<Unit> = (number * r);
operator*: <Unit> (l: i32, r: quantity<Unit>) -> quantity<Unit> = r * l;
Not only is this more verbose,
we've moved them away from similar operators,
operators which still share the dissimilarity.
I think this is the ideal:
quantity: @struct <Unit: type> type = {
number: i32;
friend operator*: (this, r: i32) -> quantity = (number * r);
friend operator*: (l: i32, this) -> quantity = r * l;
}
jcanizales
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working