-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Syntax for implementing a single-function interfaces #4711
Comments
One option that was suggested in a recent conversation was:
could be shortened to:
A few things to note:
|
Not sure I am a fan of a shorthand for this, but some thoughts on why for me:
|
Maybe not obvious from the original write up, but the idea is that this is a short hand for the full syntax: class C {
impl as Core.AddWith(D) where .ResultType = E {
fn [self: Self](other: D) -> E {
return DoAdd(self, other);
}
}
} That is, interfaces opt into this being available by having an anonymous function and all associated constants being deduced from the signature of that function in an And the expectation is that the only changes that would require updating the source would be the same ones that require updating the source today: adding a function or associated constant that must be defined / specified in the But it would require a structural change as well as the addition of the newly required function definition or associated constant value. So it's more making the required source changes a bit more invasive than introducing source changes where we wouldn't have had them previously. |
Summary of issue:
Many of the operator overload interfaces have a single function, and other interfaces are expected to commonly as well. The current
impl
definition syntax is perhaps cumbersome for this case. Perhaps we should have a convenient shortcut?In order to allow evolution of interfaces, this should apply any time the interface has one required function. If this convenient syntax is used, it should ignore functions with a default or final definition in the interface.
The text was updated successfully, but these errors were encountered: