polymorphic symmetric multiple dispatch with variance
play

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


  1. Polymorphic Symmetric Multiple Dispatch with Variance Gyunghee Park, Jaemin Hong, Guy L. Steele Jr., Sukyoung Ryu POPL '19

  2. 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 / 10

  3. 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) List b: List = SortedList(2, 4, 6) SortedList add(a, b) � 3 / 10

  4. 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) List b: List = SortedList(2, 4, 6) SortedList add(a, b) 3 / 10

  5. 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) List b: List = SortedList(2, 4, 6) SortedList add(a, b) 4 / 10

  6. 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) List b: List = SortedList(2, 4, 6) SortedList add(a, b) 5 / 10

  7. 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) List b: List = SortedList(2, 4, 6) SortedList add(a, b) 5 / 10

  8. Binary Method Problem 6 / 10 Odersky et al., Programmin in Scala (3rd Ed.) , Ch. 30 Object Equality

  9. 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) List b: List = SortedList(2, 4, 6) SortedList add(a, b) 7 / 10

  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) List b: List = SortedList(2, 4, 6) SortedList add(a, b) 7 / 10

  11. Unambiguity add(x: List, y: SortedList): List = … add(x: SortedList, y: List): List = … List a: List = SortedList(1, 3, 5) b: SortedList = SortedList(2, 4, 6) SortedList add(a, b) 8 / 10

  12. Unambiguity add(x: List, y: SortedList): List = … add(x: SortedList, y: List): List = … List a: List = SortedList(1, 3, 5) b: SortedList = SortedList(2, 4, 6) SortedList add(a, b) 8 / 10

  13. Type Preservation add(x: List, y: SortedList): SortedList = … add(x: SortedList, y: SortedList): List = … List a: List = SortedList(1, 3, 5) b: SortedList = SortedList(2, 4, 6) SortedList add(a, b) 9 / 10

  14. Type Preservation add(x: List, y: SortedList): SortedList = … add(x: SortedList, y: SortedList): List = … List a: List = SortedList(1, 3, 5) b: SortedList = SortedList(2, 4, 6) SortedList add(a, b): SortedList 9 / 10

  15. Overloading Rules 10 / 10

  16. Overloading Rules 10 / 10

Recommend


More recommend