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

7. Type Variance #37

Open
justjoheinz opened this issue Feb 21, 2016 · 1 comment
Open

7. Type Variance #37

justjoheinz opened this issue Feb 21, 2016 · 1 comment

Comments

@justjoheinz
Copy link

I think this section is either wrong or misleading:

This means that if you have a container defined as Box[A], and then use it with a Fruit in place of the type parameter A, you will not be able to insert an Apple (which IS-A Fruit) into it.

Of course I can do:

case class Box[A](value : A)
var xf : Box[Fruit] = Box(Apple)

but cannot do:

val xa : Box[Apple.type] = Box(Apple)
xf = xa

Maybe the sentence should read along the lines of:

This means that if you have a container defined as Box[A], and then expect a Box[Fruit], you will not be able to use Box[Apple], which is a fruit, because Box is invariant in the type parameter A.

And I just want to mention that the blog post is a very nice resource! I come to it or refer it fairly frequently. Thanks for putting it up.

@ktoso
Copy link
Owner

ktoso commented Feb 21, 2016

You're right on the wording! Would you be able to submit a PR addressing this? Thanks a lot in advance!

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

2 participants