Closed AndreiBarsan closed 9 years ago
K is invariant in Set, but Store defines it as contravariant. So this is a way to decouple the two and let the compiler know that.
This is a good slidedeck I think: http://www.slideshare.net/dgalichet/demystifying-scala-type-system
I see. Thanks for the info! I was actually under the impression that the Set's type parameter was actually covariant, like List
's. This StackOverflow question actually cleared that misconception up: http://stackoverflow.com/questions/676615/why-is-scalas-immutable-set-not-covariant-in-its-type
I feel a bit confused by the type constraints in the
ReadableStore
(or itsWritableStore
sibling) definitions:Why is
multiGet
parameterized by allowing any subtype ofK
to also be used as a parameter, whileget
isn't? (Sorry if the answer is obvious--I'm still learning Scala and getting to grips with its wonderful type system!)