46
Getting F-Bounded Polymorphism into Shape Ben Greenman, Fabian Muehlboeck, and Ross Tate Cornell University

Getting F-Bounded Polymorphism into Shape

  • Upload
    lirit

  • View
    25

  • Download
    2

Embed Size (px)

DESCRIPTION

Getting F-Bounded Polymorphism into Shape. Ben Greenman, Fabian Muehlboeck , and Ross Tate Cornell University. Typesafe Equality + Generic Lists?. ( Typesafe ) Equality. @override public boolean equals(Object other) { if(other instanceof String){…} else { return false; } }. - PowerPoint PPT Presentation

Citation preview

PowerPoint Presentation

Getting F-Bounded Polymorphism into ShapeBen Greenman, Fabian Muehlboeck, and Ross TateCornell University

12Typesafe Equality + Generic Lists?3(Typesafe) Equality@overridepublic boolean equals(Object other) {if(other instanceof String){}else { return false; }}Hello.equals(5)

4(Typesafe) Equalityinterface Eq { boolean equalTo(T other);}class String extends Eq { boolean equalTo(String other) {} }Hello.equalTo(5)

5(Typesafe) Equality{Hello,World!}.equalTo{Ahoi,World!}

6List (read-only)EqcovariantcontravariantList ListEq EqListEq:>:>7interface List extends Eq8interface List extends EqListListEqEqStringEqListList9List extends EqAndrewJ. Kennedy and BenjaminC. Pierce On Decidability of Nominal Subtyping with Variance, FOOL-WOOD 2007Expansive Inheritance!List extends EqListListRoss Tate, Alan Leung, and Sorin LernerTaming Wildcards in Java's Type System , PLDI 2011Nested Contravariance!List extends EqList extends Eq10Treesclass Tree extends ListAre trees equatable?11Are Trees equatable?

12Are Trees equatable?EqListListTreeEqEqListTree13Meh!14interface List extends Eq1516WHY?17interface List extends EqList18ListList

How do we use Eq?With F-bounded polymorphism!class String extends Eqclass SetNOT as type arguments!NOT for parameters!NOT for fields!NOT for local variables!NOT for return types!19ShapesMaterialsUsed inRecursive inheritance definitionsRecursive type variable constraintsUsed forType argumentsMethod parametersReturn typesFieldsVariablesStringListThrowableFileStreamEqComparableClonableSummable20All Sheep in Scotland are black21Read these 13 million lines of Code!Can I script it?NO!I mean YES!22Survey13.5 million lines of open-source generic Java code*http://qualitascorpus.comtaken primarily from the Qualitas Corpus*No class was ever both a shape and a materialfrom 60 projects- Type arguments- Method parameters- Return types- Fields & VariablesRecursive - inheritance definitions- type variable constraints23Thou shalt not mix shapesand materials!Material-Shape Separation24

25ShapesMaterialsUsed inRecursive inheritance definitionsRecursive type variable constraints

Used forType argumentsMethod parametersFieldsVariablesRecursive inheritance only through ShapesWell-founded inheritance26Well-founded Material Inheritanceclass A extends B, D {}Inheritance hierarchies defined independent of AMaterials27Well-founded Material Inheritanceclass A extends B {}class B extends A {}

class A extends List {}class B extends List {}28Decidable SubtypingWith nave algorithmsProven with a simple measure29Decidable Subtypingmaterial interface Predmaterial interface Matrix extends List30Decidable Subtyping31Decidable Subtyping32Decidable SubtypingA extends BInheritance well-founded measure function terminates33A extends EqA extends EqDecidable SubtypingAll MaterialsNo Shapes in here343536JoinsMost precise common supertypesomeBool ? 42 : Hello37JoinsInteger extends ClonableString extends ClonableClonableClonableClonable38Computable Material JoinsMaterials only: ObjectInteger extends ClonableString extends ClonablesomeBool ? 42 : Hello39MaterialJoinsA extends CB extends CFinite due to well-founded material inheritanceC40Higher Kinds4142Conditional Inheritance43Decidable SubtypingHigher KindsComputable JoinsMaterial-Shape Separation444546