-
Notifications
You must be signed in to change notification settings - Fork 691
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
Add section about variance and positions #6105
base: main
Are you sure you want to change the base?
Conversation
Visit the preview URL for this PR (updated for commit f96daa2): https://dart-dev--pr6105-glossary-variance-sep24-czn0ufpb.web.app |
Sorry about the delay in reviewing this, I hope to get to it soon! Thanks again for working on this :D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for working on this @eernstg! I'm not very familiar with these concepts, so I naturally read it from a perspective of someone brand new to these terms. As a result, my questions and suggestions might be incorrect, so please feel free to push back on anything. At the very least, I hope my confusions and potential misunderstandings can at least help you identify where readers might go astray.
I left a few other small comments for the second pass so I can validate my understanding before leaving misleading suggestions. :)
Thanks again and sorry about the delay in reviewing this! I'm super excited to have something tangible in the docs to reference for these terms, and I can see it helping others as it was already insightful to me.
src/content/resources/glossary.md
Outdated
For example, consider `List<int Function(_)>` as a template for a type | ||
where we can put different types into the location where `_` occurs. | ||
|
||
This type is contravariant in that position: For example, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider combining these two paragraphs, as the second one heavily relies on the first one. With the separation, it might not be clear what "This type" or "that position" refers to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also is the following example meant to explain why its contravariant in that position or is it because it's contravariant in that position?
My understanding is that it's an example of understanding why that position is contravariant, but it's not clear to me from reading. Perhaps flipping the order of the because clauses and starting at the Object
and int
parameter type relation, might make that more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combined the two paragraphs.
I changed the return type from int
to void
in the following examples, in order to be able to talk about int
as a type that is unambiguously associated with a single position in the type (avoiding the need to say "the first int
" vs. "the second int
" and such).
is the following example meant to explain why its contravariant in that position
The text is intended to explain how 'contravariant position' is defined, by example. This is in itself an example, because it is intended to define 'contravariant position' as well as 'covariant position', based on a generalization which the reader would probably perform automatically, based on the previous explanations. I added a paragraph where 'covariant position' is defined briefly, but explicitly, in order to improve on this situation.
The text defines 'contravariant position' by explaining why we must conclude that the overall type List<void Function(_)>
varies in the opposite direction of the variation at _
, and then states that this by definition makes the position of _
contravariant.
Co-authored-by: Parker Lougheed <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made several changes based on the review.
Resolves #5254.
Staged: https://dart-dev--pr6105-glossary-variance-sep24-czn0ufpb.web.app/resources/glossary#variance-and-variance-positions