CSE 341 Section 10 Subtyping, Review, and The Future.

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Advertisements

George Blank University Lecturer.
CSE-321 Programming Languages Subtyping POSTECH May 14, 2007 박성우.
Object-Oriented Programming CS 3360 Spring 2012 Sec , Adapted from Addison Wesley’s lecture notes (Copyright © 2004 Pearson Addison.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
CSE341: Programming Languages Lecture 26 Subtyping for OOP Dan Grossman Fall 2011.
Basic OOP Concepts and Terms
CSE341: Programming Languages Lecture 11 Type Inference Dan Grossman Winter 2013.
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
Introduction to Ruby CSE 413 Autumn 2008 Credit: Dan Grossman, CSE341.
CSE 413 Programming Languages & Implementation Hal Perkins Autumn 2012 Ruby: Multiple Inheritance, Interfaces, Mixins 1.
Comparison of OO Programming Languages © Jason Voegele, 2003.
Programming Languages and Paradigms Object-Oriented Programming.
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
Static and Dynamic Behavior CMPS Power of OOP Derives from the ability of objects to change their behavior dynamically at run time. Static – refers.
The Scala Programming Language presented by Donna Malayeri.
1 Structure and Interpretation of Computer Programs Modularity, Objects, and State (part 1) Abelson & Sussman 2 UC San Diego CSE 294 May 11, 2011 Barry.
CSE 425: Object-Oriented Programming I Object-Oriented Programming A design method as well as a programming paradigm –For example, CRC cards, noun-verb.
CSC 580 – Theory of Programming Languages, Spring, 2009 Week 9: Functional Languages ML and Haskell, Dr. Dale E. Parson.
CSE 413 Programming Languages & Implementation Hal Perkins Autumn 2012 Late binding and dynamic dispatch (Based on CSE 341 slides by Dan Grossman) 1.
Chapter 12 Support for Object oriented Programming.
Objects & Dynamic Dispatch CSE 413 Autumn Plan We’ve learned a great deal about functional and object-oriented programming Now,  Look at semantics.
Types in programming languages1 What are types, and why do we need them?
Compiling Objects in Class-Based Languages CS 153: Compilers.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Chapter 12 Support for Object-Oriented Programming.
Object-Oriented Programming Chapter Chapter
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
Object Oriented Programming
ISBN Object-Oriented Programming Chapter Chapter
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
CSE341: Programming Languages Lecture 23 Multiple Inheritance, Mixins, Interfaces, Abstract Methods Dan Grossman Spring 2013.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
Interfaces, Mixins, & Multiple Inheritance CSE 413 Autumn 2008 Credit: Dan Grossman, CSE341, Sp08.
Overview of C++ Polymorphism
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Subtying Kangwon National University 임현승 Programming Languages These slides were originally created by Prof. Sungwoo Park at POSTECH.
ISBN Chapter 12 Support for Object-Oriented Programming.
CSC 520 – Advanced Object Oriented Programming, Fall, 2010 Thursday, September 30 Week 5, Generics and Inheritance Techniques, Meyer Ch. 10 & 16.
A Concrete Presentation on Abstract Classes and Methods, Interfaces, and Polymorphism CSC 202.
CSE341: Programming Languages Lecture 11 Type Inference
CSE341: Programming Languages Lecture 23 Multiple Inheritance, Mixins, Interfaces, Abstract Methods James Wilcox Winter 2017.
Types of Programming Languages
ATS Application Programming: Java Programming
CSE341: Programming Languages Lecture 23 Multiple Inheritance, Mixins, Interfaces, Abstract Methods Zach Tatlock Winter 2018.
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Winter 2013.
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 23 Multiple Inheritance, Mixins, Interfaces, Abstract Methods Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 23 Multiple Inheritance, Mixins, Interfaces, Abstract Methods Dan Grossman Spring 2016.
Objects and Aspects: What we’ve seen so far
CSE 341 Section 5 Winter 2018.
CSE341: Programming Languages Lecture 23 Multiple Inheritance, Mixins, Interfaces, Abstract Methods Dan Grossman Spring 2017.
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Zach Tatlock Winter 2018.
Support for Object-Oriented Programming
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Spring 2017.
Overview of C++ Polymorphism
Basic OOP Concepts and Terms
CSE341: Programming Languages Lecture 23 Multiple Inheritance, Mixins, Interfaces, Abstract Methods Dan Grossman Autumn 2017.
Lecture 10 Concepts of Programming Languages
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Spring 2013.
CSE341: Programming Languages Lecture 11 Type Inference
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Spring 2019.
CSE341: Programming Languages Lecture 23 Multiple Inheritance, Mixins, Interfaces, Abstract Methods Dan Grossman Spring 2019.
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
Presentation transcript:

CSE 341 Section 10 Subtyping, Review, and The Future

Outline 1.Subtyping Overview 2.Review Topics Questions? 3.The Future Languages Courses

Records Overview Creation {f0=e0, f1=e1,..., fn=en} Access/Update e.fielde1.field = e2 Type Signature {f1:t1, f2:t2,..., fn:tn} f* = field name e* = expression t* = type

Subtyping Relation t1 <: t2 t1 extends t2 t1 is a subtype of t2 Subtyping Overview Additional Type Rule If t1 <: t2 and e has type t1, then e also has type t2 Record Subtyping Rules Width subtyping: A supertype can have fewer fields Permutation subtyping: A supertype can have reordered fields Transitivity: If t1 <: t2 and t2 <: t3, then t1 <: t3. Reflexivity: t <: t for any t (anything is a subtype of itself)

Function Types covariant: preserves subtype relation of types contravariant: reverses the subtype relation of types Function Subtyping Rules If t2 t2 t4. or a more tangible example.. If Cat <: Animal and Teacher <: Person, then Person -> Cat Animal. Function subtyping is covariant for their return types Function subtyping is contravariant for their argument types

Objects (in relation to records) Objects are basically the same as records except there is a distinction between mutable and immutable fields. Mutable fields are instance variables Immutable fields are methods Subtyping of objects happens almost the same way as records e.g. Java/C# disallow contravariant method arguments The implicit self parameter in methods is covariant (unlike explicit arguments which are contravariant)

subclassing vs subtyping Java confuses these ideas as a matter of convenience, but you should keep these ideas separate Classes: define an object’s behavior Types: describes what fields an object has and what messages it can respond to Subclassing: inherits behavior, modifies behavior via extension and overriding Subtyping: is a question of suitability and what we want to flag as a type error

Pop Quiz Are these sound or not? (if not, give a counter-example) When overriding a method, we can change an argument type to be a supertype of what it was in the superclass’ method. Sound (contravariant argument types) When overriding a method, we can change an argument type to be a subtype of what it was in the superclass’ method. Unsound (covariant argument types) When overriding a method, we can change the result type to be a supertype of what it was in the superclass’ method. Unsound (contravariant return types)

Pop Quiz (continued) Are these sound or not? (if not, give a counter-example) When overriding a method, we can change the result type to be a subtype of what it was in the superclass’ method. Sound (covariant return types) A subclass can change the type of a (mutable) field to be a subtype of what it was in the superclass. (This is changing the type of a field, not adding a second field.) Unsound (depth subtyping on mutable fields) A subclass can change the type of a (mutable) field to be a supertype of what it was in the superclass. (This is changing the type of a field, not adding a second field.) Unsound (depth subtyping on mutable fields)

At a Glance Benefits of no mutation Algebraic datatypes, pattern matching Higher-order functions; closures; tail recursion Lexical scope Currying; syntactic sugar Equivalence and side-effects Type inference Dynamic vs. static typing Laziness, streams, and memoization Macros Dynamic dispatch; double-dispatch Multiple inheritance, interfaces, and mixins OO vs. functional decomposition and extensibility Subtyping for records, functions, and objects Class-based subtyping Parametric polymorphism; bounded polymorphism

Questions? What are your questions?

Some Exciting Developments… Rust (a “better” C / C++) Type inference, higher-order functions Concurrency “baked-in” Eliminates null pointer exceptions Improved memory management Scala (a “better” Java?) FP + OOP + static typing + JVM Clojure (modern, concurrency-focused Lisp hosted on the JVM) Persistent, immutable data structures Concurrency primitives with an STM: atoms, vars, agents; refs Haskell (lazy, pure ML-like language) Category theory: Monads, Monoids, Functors,... Type classes, parsec, super-awesome type system,... And many more! Haxe, Groovy, Dart, Go, ecmascripten / asm.js, …

Future Courses CSE333 – Systems Programming CSE401 – Compilers CSE501 – Implementation of Programming Languages CSE505 – Concepts of Programming Languages