Title
Taming the wildcards: combining definition- and use-site variance
Abstract
Variance allows the safe integration of parametric and subtype polymorphism. Two flavors of variance, definition-site versus use-site variance, have been studied and have had their merits hotly debated. Definition-site variance (as in Scala and C#) offers simple type-instantiation rules, but causes fractured definitions of naturally invariant classes; Use-site variance (as in Java) offers simplicity in class definitions, yet complex type-instantiation rules that elude most programmers. We present a unifying framework for reasoning about variance. Our framework is quite simple and entirely denotational, that is, it evokes directly the definition of variance with a small core calculus that does not depend on specific type systems. This general framework can have multiple applications to combine the best of both worlds: for instance, it can be used to add use-site variance annotations to the Scala type system. We show one such application in detail: we extend the Java type system with a mechanism that modularly infers the definition-site variance of type parameters, while allowing use-site variance annotations on any type-instantiation. Applying our technique to six Java generic libraries (including the Java core library) shows that 20-58 (depending on the library) of generic definitions are inferred to have single-variance; 8-63% of method signatures can be relaxed through this inference, and up to 91% of existing wildcard annotations are unnecessary and can be elided.
Year
DOI
Venue
2011
10.1145/1993498.1993569
PLDI
Keywords
Field
DocType
specific type system,java type system,java core library,java generic library,use-site variance,complex type-instantiation rule,use-site variance annotation,scala type system,type parameter,definition-site variance,type system,polymorphism,variance,wildcards
Wildcard,Programming language,Scala,Wildcard character,Inference,Computer science,Theoretical computer science,Parametric statistics,Invariant (mathematics),Java
Conference
Volume
Issue
ISSN
46
6
0362-1340
Citations 
PageRank 
References 
4
0.43
9
Authors
3
Name
Order
Citations
PageRank
John Altidor161.15
Shan Shan Huang220214.60
Yannis Smaragdakis32247147.50