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

Variance annotations #72

Closed
ccheneson opened this issue Aug 5, 2017 · 5 comments
Closed

Variance annotations #72

ccheneson opened this issue Aug 5, 2017 · 5 comments

Comments

@ccheneson
Copy link

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] .

@davegurnell
Copy link
Contributor

davegurnell commented Aug 7, 2017 via email

@ghisvail
Copy link
Contributor

ghisvail commented Aug 7, 2017

If C is a supertype of B , Foo[C] is a subtype of Foo[B]

This the correct definition of contravariance. See essential-scala section 5.6.1 which briefly mentions that contravariance is used for function arguments. The issue should be closed.

@cchphotobox
Copy link

Thanks for your response. It seems I can not close this issue (No "Close" button). Sorry for the misunderstanding

@davegurnell
Copy link
Contributor

davegurnell commented Aug 7, 2017

@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!

@davegurnell
Copy link
Contributor

I've made two changes in c7cf137 in an attempt to improve the clarity here:

  • I've changed the wording in the definitions so they both say "subtype" in all places, instead of mixtures of "subtype" and "supertype".

  • I've added some quick examples.

If you have time, please let me know what you think!

davegurnell pushed a commit that referenced this issue Sep 12, 2017
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

No branches or pull requests

4 participants