Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

eernstg
Copy link
Member

@eernstg eernstg commented Sep 24, 2024

@dart-github-bot
Copy link
Collaborator

dart-github-bot commented Sep 24, 2024

Visit the preview URL for this PR (updated for commit f96daa2):

https://dart-dev--pr6105-glossary-variance-sep24-czn0ufpb.web.app

@parlough
Copy link
Member

parlough commented Oct 3, 2024

Sorry about the delay in reviewing this, I hope to get to it soon! Thanks again for working on this :D

Copy link
Member

@parlough parlough left a 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 Show resolved Hide resolved
src/content/resources/glossary.md Outdated Show resolved Hide resolved
src/content/resources/glossary.md Outdated Show resolved Hide resolved
src/content/resources/glossary.md Outdated Show resolved Hide resolved
src/content/resources/glossary.md Outdated Show resolved Hide resolved
src/content/resources/glossary.md Outdated Show resolved Hide resolved
src/content/resources/glossary.md Outdated Show resolved Hide resolved
Comment on lines 374 to 377
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,
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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.

src/content/resources/glossary.md Outdated Show resolved Hide resolved
src/content/resources/glossary.md Outdated Show resolved Hide resolved
Copy link
Member Author

@eernstg eernstg left a 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.

@parlough parlough self-requested a review October 8, 2024 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Covariant / Covariance definition
3 participants