-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Find a way to reintroduce Self types without the complexity #643
Comments
Another example is the
This requires implementations like so:
In contrast, with
This does however introduce a new challenge: if we cast a type to |
I agree with your For example, this would trivially make sense to test equality:
(I realize that this brings up a larger discussion about the way that inko handles implementing traits on types and that this currently doesn't work for other reasons. Attempting to implement The way that Rust handles this is by using the |
@klieth To support what you're referring to, we'd need to add support for overloading methods based on the traits they originate from. This is something I want to avoid due to the complexity it brings with it. Similarly, default type parameter values is something I also want to avoid, again to keep the compiler and type system complexity at a level that I'm comfortable with. At some point in the future that may change, but it won't be the case for at least a few more years (if ever). |
Description
Inko used to have support for
Self
types, but this was removed due to the complexity and bugs this introduced to the type system. This change however makes certain patterns difficult or even impossible to implement. The traitstd.clone.Clone
is a good example of this. Ideally, the trait is defined as follows:This way if you use e.g.
String.clone
orFoo.clone
you get aString
orFoo
back. This currently isn't possible, so we have to use generics instead:In this particular case it works, but results in a bit of type boilerplate/redundancy:
Versus just the following:
While this case isn't too difficult, in other cases it can get really messy, requiring extensive workarounds.
I would like to explore options to reintroduce
Self
types in some reduced capacity, ideally without having to consider them in every place a type may occur. This means having to restrictSelf
types to trait definitions, such that we can more easily substitute them with real types.Related work
No response
The text was updated successfully, but these errors were encountered: