Presentation is loading. Please wait.

Presentation is loading. Please wait.

Subtying Kangwon National University 임현승 4473001-1 Programming Languages These slides were originally created by Prof. Sungwoo Park at POSTECH.

Similar presentations


Presentation on theme: "Subtying Kangwon National University 임현승 4473001-1 Programming Languages These slides were originally created by Prof. Sungwoo Park at POSTECH."— Presentation transcript:

1 Subtying Kangwon National University 임현승 4473001-1 Programming Languages These slides were originally created by Prof. Sungwoo Park at POSTECH.

2 2 Key Features of Object-Oriented Languages Multiple representation –different methods of the same name –dynamic dispatch Encapsulation –Only an object's own methods can see private data. Inheritance –classes, subclasses,... Subtyping –interface, interface extension

3 3 Outline Overview V Principle of subtyping Subtyping relations Coercion semantics

4 4 Principle of Subtyping

5 5 Examples

6 6 Basic Rules Reflexivity and transitivity Rule of subsumption

7 7 Subset Semantics for Subtyping Example –32-bit word for nat –32-bit word for int –64-bit word for float

8 8 Outline Overview V Principle of subtyping V Subtyping relations Coercion semantics

9 9 Setup

10 10 Subtyping for Product Types

11 11 Subtyping for Sum Types

12 12 Subtyping for Function Types

13 13 Subtyping for Reference Types

14 You are all so gullible!

15 15 Wrong Subtyping Rules!

16 16

17 17

18 18 Subtyping for Function Types Covariant in return types B and B' Contravariant in argument types A and A'

19 19 Dereferencing ref A

20 20 Assigning to ref A

21 21 Subtyping for Reference Types

22 22 Subtyping for Array Types Array types = extension of reference types Subtyping for array types in Java –runtime overhead of dynamic tag-checks.

23 Subtyping for Java Array Types class Animal {} class Dog extends Animal {} class Cat extends Animal {} class Main { public static void main(String[] args) { Dog[] dogs = new Dog[1]; dogs[0] = new Dog(); Animal[] animals = dogs; animals[0] = new Cat(); } 23 Exception in thread "main" java.lang.ArrayStoreException: Cat at Main.main

24 24 Outline Overview V Principle of subtyping V Subtyping relations V Coercion semantics

25 25 Coercion Semantics for Subtyping Example –32-bit word for int –64-bit word for float

26 26 Coercion Subtyping Judgment

27 27 Coherence


Download ppt "Subtying Kangwon National University 임현승 4473001-1 Programming Languages These slides were originally created by Prof. Sungwoo Park at POSTECH."

Similar presentations


Ads by Google