Skip to content

Typing Generic mutability methods compatible with class inheritence #1595

Answered by Daverball
charles-paperman asked this question in Q&A
Discussion options

You must be logged in to vote

This sort of thing requires higher kinded types, which are quite challenging to implement, especially once you consider composability with other typing features. There has been some discussion about allowing Self to be higher kinded in a limited scope, but no concrete proposals have come out of it so far, since it requires careful consideration about what happens in subclasses that no longer have a type var.

For now you just can't do this, so you will have to pick your poison. I think returning TypedList[K] is the best option, it forces you to override in subclasses if you need the container type to match, but it's at least never a wrong type, it's just not as precise as it could be.

In y…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@charles-paperman
Comment options

Answer selected by charles-paperman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants