-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arithmetics operator for "point-vector" types. #14346
Comments
This issue has been marked as stale due to inactivity for the last 90 days. |
This is still relevant |
This issue has been marked as stale due to inactivity for the last 90 days. |
this is still relevant (for solidity experimental I guess) |
The restriction here is very much deliberate both to reduce the minimal required expressivity for Solidity's type system logically (in experimental Solidity, the request would boil down to multi-parameter type classes/traits versus single-parameter type classes, which is a significant difference in complexity), but also to avoid the inevitable ambiguities you can introduce with a more relaxed mechanism on the language level. I won't close the issue, since for independent reasons we may still end up with sufficient type system complexity to accommodate this in theory - but even then I'd be hesitant to expose that expressivity on the operator level (although introducing an additional operator for scalar vector space multiplication may be an option, if we find a good syntactic choice). So there may be space to accommodate this one way or another in the future, but it is generally in the first instance a non-goal. |
This issue has been marked as stale due to inactivity for the last 90 days. |
Hi everyone! This issue has been automatically closed due to inactivity. |
Abstract
Allow the definition of the
add
(andsub
) operators with 2 differents input typesMotivation
Two basic concepts in geometry, are Points and Vectors. It makes sens to add, or even subtract 2 vectors, giving a new vector. It also makes sens to add a vector to a point, giving a new point. On the other hand, it does not make sens to add to point (if you do so, you are probably assuming that a point is equivalent to the vector from the origin to it).
The same can be said of Timepoints and Durations, which are basically the same object in one dimension.
In order to improve the security of time arithmetics (clearly distinguishing times and duration using dedicated UDVT), I wanted to define
and then define the following functions:
I then wanted to defined these function as global operators:
and this is when I got the following errors:
Note that while the first one is very clear, the second one asks "one or two parameters of type Timepoint" ... which it does have
Specification
Allow the definition of arithmetic types (add, sub, mul, div, modulo?) that have
function operator_name(A a, B b) pure returns (A)
Backwards Compatibility
N/A
The text was updated successfully, but these errors were encountered: