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
proposal: Go 2: apply type redefinition recursively #23246
Comments
Do you have an example use case you’ve faced, and an example implementation using this feature?
|
Here is an example that doesn't compile with Go 1:
Wrapping I previously needed this because I had a tree structure that had some basic traversal functions, and I wanted to build upon it by extending the type. However, that design has changed enough that I don't need this feature any more. But I remembered that this would have made a few things convenient at that time. So, maybe others could benefit. |
Playing my own devil's advocate. This proposal doesn't extend well for higher depths:
And a murkier variant:
In the above cases, it becomes hard to come up with a good interpretation of I can close this issue unless I hear other thoughts. |
I also agree that the rules for this feature in the language would either be simple yet flawed, or complicated. As for the issue itself, I think it's ok to leave it open for Go2 so that it's not forgotten if and when a broader feature is designed, such as generics. It can always be closed at a later time. |
For a traversable tree of diverse types why not use an interface as the node type? |
This is a step toward generic types. Let's take a full step instead of a small one. This is also not Go 1 compatible, but in a fairly subtle way. |
If you have a recursive type like a LinkList:
Then a new type based on LinkList:
should expand to:
This change by itself is not very useful. However, if we also allowed casting of LinkList2 to LinkList, it will allow methods of LinkeList2 to reuse methods of LinkList.
Obviously, we should consider this only if it doesn't break other parts of the language.
The text was updated successfully, but these errors were encountered: