Download presentation
Presentation is loading. Please wait.
Published byBrittney Lewis Modified over 9 years ago
1
Getting F-Bounded Polymorphism into Shape Ben Greenman, Fabian Muehlboeck, and Ross Tate Cornell University
3
Typesafe Equality + Generic Lists?
4
(Typesafe) Equality @override public boolean equals(Object other) { if(other instanceof String){…} else { return false; } } “Hello”.equals(5)
5
(Typesafe) Equality interface Eq { boolean equalTo(T other); } class String extends Eq { boolean equalTo(String other) {…} … } “Hello”.equalTo(5)
6
(Typesafe) Equality {“Hello”,”World!”}.equalTo {“Ahoi”,”World!”}
7
List (read-only)Eq covariant contravariant List List Eq Eq List Eq :>
8
interface List extends Eq >>
9
interface List extends Eq >> List <:Eq > Eq >><:Eq > List <:List > String<:Eq Done! List List > Eq >>Eq > StringEq List List >
10
List extends Eq >> Andrew J. Kennedy and Benjamin C. Pierce On Decidability of Nominal Subtyping with Variance, FOOL-WOOD 2007 Expansive Inheritance! List extends Eq >> List List > Ross Tate, Alan Leung, and Sorin Lerner Taming Wildcards in Java's Type System, PLDI 2011 Nested Contravariance! List extends Eq >>
11
Trees class Tree extends List Are trees equatable?
12
Are Trees equatable?
13
Tree<:List > List <:List > Tree<:Eq List <:Eq Eq >><:Eq Tree<:List > Eq List >List Tree Eq Eq >> List > Tree
14
Meh!
15
interface List extends Eq >>
17
WHY?
18
interface List extends Eq >> List >
19
List List > How do we use Eq ? With F-bounded polymorphism! class String extends Eq class Set > NOT as type arguments! NOT for parameters! NOT for fields! NOT for local variables! NOT for return types!
20
ShapesMaterials Used in Recursive inheritance definitions Recursive type variable constraints Used for Type arguments Method parameters Return types Fields Variables String List Throwable FileStream Eq Comparable Clonable Summable
21
All Sheep in Scotland are black
22
Read these 13 million lines of Code! Can I script it? NO! I mean… YES!
23
Survey 13.5 million lines of open-source generic Java code *http://qualitascorpus.com taken primarily from the Qualitas Corpus* No class was ever both a shape and a material from 60 projects - Type arguments - Method parameters - Return types - Fields & Variables Recursive - inheritance definitions - type variable constraints
24
Thou shalt not mix shapes and materials! Material-Shape Separation
26
ShapesMaterials Used in Recursive inheritance definitions Recursive type variable constraints Used for Type arguments Method parameters Fields Variables Recursive inheritance only through Shapes Well-founded inheritance
27
Well-founded Material Inheritance class A extends B, D {…} Inheritance hierarchies defined independent of A Materials
28
Well-founded Material Inheritance class A extends B {…} class B extends A {…} class A extends List {…} class B extends List {…}
29
Decidable Subtyping With naïve algorithms Proven with a simple measure
30
Decidable Subtyping Pred ><:Pred > Matrix <:List List ><:List <:Object Done! material interface Pred material interface Matrix extends List >
31
Decidable Subtyping Pred ><:Pred > Matrix <:List List ><:List <:Object Done!
32
Decidable Subtyping Pred ><:Pred > Matrix <:List List ><:List <:Object Done!
33
Decidable Subtyping A extends B > Inheritance well-founded measure function terminates
34
A extends Eq >> Decidable Subtyping All Materials No Shapes in here
37
Joins Most precise common supertype someBool ? 42 : “Hello”
38
Joins Integer extends Clonable String extends Clonable Clonable Clonable > Clonable >>
39
Computable Material Joins Materials only: Object Integer extends Clonable String extends Clonable someBool ? 42 : “Hello”
40
Material Joins A extends C B extends C > Finite due to well-founded material inheritance C
41
Higher Kinds
43
Conditional Inheritance
44
Decidable Subtyping Higher Kinds Computable Joins Material-Shape Separation
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.