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

Slides:



Advertisements
Similar presentations
Transposing F to C Transposing F to C Andrew Kennedy & Don Syme Microsoft Research Cambridge, U.K.
Advertisements

Taming Wildcards in Javas Type System Ross Tate Alan Leung Sorin Lerner University of California, San Diego.
Overriding CMPS Overriding Recall, a method in a child class overrides a method in the parent class, if it has the same name and type signature.
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright © Instructors.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Generic programming in Java
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Cmp Sci 187: Midterm Review Based on Lecture Notes.
Polymorphism. Lecture Objectives To understand the concept of polymorphism To understand the concept of static or early binding To understand the concept.
Taming the Wildcards: Combining Definition- and Use-Site Variance – Altidor John Altidor Taming the Wildcards: Combining Definition- and Use-Site Variance.
Types in programming languages What are types, and why do we need them? Types in programming languages1.
Inheritance One of the biggest advantages of object-oriented design is that of inheritance. A class may be derived from another class, the base class.
Types(2). 2 Recursive Problems  One or more simple cases of the problem have a straightforward, nonrecusive solution  The other cases can be redefined.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
Polymorphism & Interfaces
The Scala Programming Language presented by Donna Malayeri.
CMSC 202 Generics. Nov Generalized Code One goal of OOP is to provide the ability to write reusable, generalized code. Polymorphic code using.
1 COSC3557: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University.
Object-oriented Programming in Java. What is OOP?  The goal is (subtype) polymorphism  Achieved by Classes (user-defined types) Classes (user-defined.
Self Type Constructors Atsushi Igarashi Kyoto University Joint work with Chieri Saito 1.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 12: Subtyping Rules What’s the.
More on Polymorphism. Ever have one of those days?
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures for Java William H. Ford William R. Topp Chapter 5 Generic.
“The beauty of empowering others is that your own power is not diminished in the process.” – Barbara Colorose Thought for the Day.
Types in programming languages1 What are types, and why do we need them?
Lecture 4 Generic programming Advanced Java Programming 1 dr hab. Szymon Grabowski dr inż. Wojciech Bieniecki
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
Cs205: engineering software university of virginia fall 2006 Subtyping and Inheritance David Evans Quiz Friday: classes through.
Parametric Polymorphism and Java Generics. Announcements One day extension on HW5 Because of an error in my HW5 config HW6 out, due November 10 Grades.
CS 151: Object-Oriented Design November 12 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
(c) University of Washington06-1 CSC 143 Java Inheritance Tidbits.
1 / 71 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 4 Programming Fundamentals using Java 1.
Zach Tatlock / Winter 2016 CSE 331 Software Design and Implementation Lecture 13 Generics 1.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
CSC142 NN 1 CSC 142 Overriding methods from the Object class: equals, toString.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 10 Inheritance and Polymorphism.
COMP Inheritance and Polymorphism Yi Hong June 09, 2015.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
OOP Tirgul 10. What We’ll Be Seeing Today  Generics – A Reminder  Type Safety  Bounded Type Parameters  Generic Methods  Generics and Inner Classes.
JAVA GENERICS Lecture 16 CS2110 – Spring 2016 Photo credit: Andrew Kennedy.
Object-Oriented Concepts
Types CSCE 314 Spring 2016.
Object-oriented Programming in Java
CSC 205 Java Programming II
Lecture 17: Polymorphism (Part II)
Lecture 2 of Computer Science II
INF3110: Exercises Part 6 Object Orientation Comments and solutions
Continuing Chapter 11 Inheritance and Polymorphism
CS 302 Week 11 Jim Williams, PhD.
Variables as Remote Control
Subtyping Rules David Evans cs205: engineering software BlackBear
User-Oriented Language Design
An Introduction to Java – Part II
Extending Classes.
Building Java Programs
Generic programming in Java
Lecture 18: Polymorphism (Part II)
The structure of programming
Chapter 11 Inheritance and Polymorphism Part 2
Lecture 13: Subtyping Rules Killer Bear Climber
PROGRAMMING IN HASKELL
Presentation transcript:

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

Typesafe Equality + Generic Lists?

(Typesafe) public boolean equals(Object other) { if(other instanceof String){…} else { return false; } } “Hello”.equals(5)

(Typesafe) Equality interface Eq { boolean equalTo(T other); } class String extends Eq { boolean equalTo(String other) {…} … } “Hello”.equalTo(5)

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

List (read-only)Eq covariant contravariant List List Eq Eq List Eq :>

interface List extends Eq >>

interface List extends Eq >> List <:Eq > Eq >><:Eq > List <:List > String<:Eq Done! List List > Eq >>Eq > StringEq List List >

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 >>

Trees class Tree extends List Are trees equatable?

Are Trees equatable?

Tree<:List > List <:List > Tree<:Eq List <:Eq Eq >><:Eq Tree<:List > Eq List >List Tree Eq Eq >> List > Tree

Meh!

interface List extends Eq >>

WHY?

interface List extends Eq >> List >

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!

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

All Sheep in Scotland are black

Read these 13 million lines of Code! Can I script it? NO! I mean… YES!

Survey 13.5 million lines of open-source generic Java code * 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

Thou shalt not mix shapes and materials! Material-Shape Separation

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

Well-founded Material Inheritance class A extends B, D {…} Inheritance hierarchies defined independent of A Materials

Well-founded Material Inheritance class A extends B {…} class B extends A {…} class A extends List {…} class B extends List {…}

Decidable Subtyping With naïve algorithms Proven with a simple measure

Decidable Subtyping Pred ><:Pred > Matrix <:List List ><:List <:Object Done! material interface Pred material interface Matrix extends List >

Decidable Subtyping Pred ><:Pred > Matrix <:List List ><:List <:Object Done!

Decidable Subtyping Pred ><:Pred > Matrix <:List List ><:List <:Object Done!

Decidable Subtyping A extends B > Inheritance well-founded  measure function terminates

A extends Eq >> Decidable Subtyping All Materials No Shapes in here

Joins Most precise common supertype someBool ? 42 : “Hello”

Joins Integer extends Clonable String extends Clonable Clonable Clonable > Clonable >>

Computable Material Joins Materials only: Object Integer extends Clonable String extends Clonable someBool ? 42 : “Hello”

Material Joins A extends C B extends C > Finite due to well-founded material inheritance C

Higher Kinds

Conditional Inheritance

Decidable Subtyping Higher Kinds Computable Joins Material-Shape Separation