Polymorphic Symmetric Multiple Dispatch with Variance Gyunghee Park, - - PowerPoint PPT Presentation

polymorphic symmetric multiple dispatch with variance
SMART_READER_LITE
LIVE PREVIEW

Polymorphic Symmetric Multiple Dispatch with Variance Gyunghee Park, - - PowerPoint PPT Presentation

Polymorphic Symmetric Multiple Dispatch with Variance Gyunghee Park, Jaemin Hong, Guy L. Steele Jr., Sukyoung Ryu POPL '19 Method Overloading add(x: Int, y: Int): Int = add(x: List, y: List): List = add(x: SortedList, y: List):


slide-1
SLIDE 1

Polymorphic Symmetric Multiple Dispatch with Variance

Gyunghee Park, Jaemin Hong, Guy L. Steele Jr., Sukyoung Ryu POPL '19

slide-2
SLIDE 2

/ 10

Method Overloading

add(x: Int, y: Int): Int = … add(x: List, y: List): List = … add(x: SortedList, y: List): SortedList = … add(x: SortedList, y: SortedList): SortedList = …

2

slide-3
SLIDE 3

/ 10

Method Dispatch

add(x: Int, y: Int): Int = … add(x: List, y: List): List = … add(x: SortedList, y: List): SortedList = … add(x: SortedList, y: SortedList): SortedList = … a: List = SortedList(1, 3, 5) b: List = SortedList(2, 4, 6) add(a, b)

3

SortedList List

slide-4
SLIDE 4

/ 10

Method Dispatch

add(x: Int, y: Int): Int = … add(x: List, y: List): List = … add(x: SortedList, y: List): SortedList = … add(x: SortedList, y: SortedList): SortedList = … a: List = SortedList(1, 3, 5) b: List = SortedList(2, 4, 6) add(a, b)

3

SortedList List

slide-5
SLIDE 5

/ 10

Static Dispatch

add(x: Int, y: Int): Int = … add(x: List, y: List): List = … add(x: SortedList, y: List): SortedList = … add(x: SortedList, y: SortedList): SortedList = … a: List = SortedList(1, 3, 5) b: List = SortedList(2, 4, 6) add(a, b)

4

SortedList List

slide-6
SLIDE 6

/ 10

Single Dispatch

add(x: Int, y: Int): Int = … add(x: List, y: List): List = … add(x: SortedList, y: List): SortedList = … add(x: SortedList, y: SortedList): SortedList = … a: List = SortedList(1, 3, 5) b: List = SortedList(2, 4, 6) add(a, b)

5

SortedList List

slide-7
SLIDE 7

/ 10

Single Dispatch

add(x: Int, y: Int): Int = … add(x: List, y: List): List = … add(x: SortedList, y: List): SortedList = … add(x: SortedList, y: SortedList): SortedList = … a: List = SortedList(1, 3, 5) b: List = SortedList(2, 4, 6) add(a, b)

5

SortedList List

slide-8
SLIDE 8

/ 10

Binary Method Problem

6

Odersky et al., Programmin in Scala (3rd Ed.), Ch. 30 Object Equality

slide-9
SLIDE 9

/ 10

Symmetric Multiple Dispatch

add(x: Int, y: Int): Int = … add(x: List, y: List): List = … add(x: SortedList, y: List): SortedList = … add(x: SortedList, y: SortedList): SortedList = … a: List = SortedList(1, 3, 5) b: List = SortedList(2, 4, 6) add(a, b)

7

SortedList List

slide-10
SLIDE 10

/ 10

add(x: Int, y: Int): Int = … add(x: List, y: List): List = … add(x: SortedList, y: List): SortedList = … add(x: SortedList, y: SortedList): SortedList = … a: List = SortedList(1, 3, 5) b: List = SortedList(2, 4, 6) add(a, b)

7

SortedList List

Symmetric Multiple Dispatch

slide-11
SLIDE 11

/ 10

Unambiguity

8

add(x: List, y: SortedList): List = … add(x: SortedList, y: List): List = … a: List = SortedList(1, 3, 5) b: SortedList = SortedList(2, 4, 6) add(a, b) SortedList List

slide-12
SLIDE 12

/ 10

Unambiguity

add(x: List, y: SortedList): List = … add(x: SortedList, y: List): List = … a: List = SortedList(1, 3, 5) b: SortedList = SortedList(2, 4, 6) add(a, b) SortedList List

8

slide-13
SLIDE 13

/ 10

Type Preservation

add(x: List, y: SortedList): SortedList = … add(x: SortedList, y: SortedList): List = … a: List = SortedList(1, 3, 5) b: SortedList = SortedList(2, 4, 6) add(a, b) SortedList List

9

slide-14
SLIDE 14

/ 10

Type Preservation

add(x: List, y: SortedList): SortedList = … add(x: SortedList, y: SortedList): List = … a: List = SortedList(1, 3, 5) b: SortedList = SortedList(2, 4, 6) add(a, b): SortedList SortedList List

9

slide-15
SLIDE 15

/ 10

Overloading Rules

10

slide-16
SLIDE 16

/ 10

Overloading Rules

10