-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
Variance annotations #72
Comments
Contravariance works the other way around. Take a look in Essential Scala
in the section on variance. That should explain it.
…On Sat, 5 Aug 2017 at 21:21, Cyril Cheneson ***@***.***> wrote:
Under the section "Controlling Instance Selections", it recaps 3 cases for
addition of variance annotations:
A type with an unannotated parameter Foo[A] is invariant in A .
This means there is no rela onship between Foo[B] and Foo[C]
no ma er what the sub- or super-type rela onship is between B
and C .
• A type with a parameter Foo[+A] is covariant in A .
If C is a subtype of B , Foo[C] is a subtype of Foo[B] .
• A type with a parameter Foo[-A] is contravariant in A .
If C is a supertype of B , Foo[C] is a subtype of Foo[B] .
Should the last statement be
If C is a supertype of B , Foo[C] is a supertype of Foo[B] .
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#72>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AAOI58saAT5KkB_R1iultd23Yk_HdFCYks5sVM7SgaJpZM4OujhI>
.
|
This the correct definition of contravariance. See |
Thanks for your response. It seems I can not close this issue (No "Close" button). Sorry for the misunderstanding |
@ccheneson @cchphotobox No worries -- thanks for submitting the issue. You're not the first to mention this. Variance is one of the more esoteric parts of Scala's type system -- it confuses loads of people. In fact, I think I'll add a note to clarify the situation. If it's being picked up by multiple people, it's worth addressing directly. I'll leave this ticket open as a reminder. Please do post again if you spot anything else -- every bit of feedback is useful! |
I've made two changes in c7cf137 in an attempt to improve the clarity here:
If you have time, please let me know what you think! |
Under the section "Controlling Instance Selections", it recaps 3 cases for addition of variance annotations:
Should the last statement be
The text was updated successfully, but these errors were encountered: