Variant Ownership with Existential Types Nicholas Cameron Sophia

  • Slides: 17
Download presentation
Variant Ownership with Existential Types Nicholas Cameron Sophia Drossopoulou Imperial College London 1

Variant Ownership with Existential Types Nicholas Cameron Sophia Drossopoulou Imperial College London 1

Outline • Variant ownership • Existential types for variance • Combine with generics for

Outline • Variant ownership • Existential types for variance • Combine with generics for expressiveness 2

class List<owner, dat> { Object<dat> datum; List<owner, dat> next; } List<o 1, o 2>

class List<owner, dat> { Object<dat> datum; List<owner, dat> next; } List<o 1, o 2> [email protected] ic. ac. uk 3

GUI e. g. window panel 1 panel 2 button 1 button 3 button 2

GUI e. g. window panel 1 panel 2 button 1 button 3 button 2 button 4 4

Subtype Variance class Window<o> {. . . void render(Panel<this> p) { List<this, p> all.

Subtype Variance class Window<o> {. . . void render(Panel<this> p) { List<this, p> all. Widgets =. . . ; . . . } [email protected] ic. ac. uk 5

Subtype Variance class Window<o> {. . . void render(Panel<this> p) { List<this, p> all.

Subtype Variance class Window<o> {. . . void render(Panel<this> p) { List<this, p> all. Widgets =. . . ; . . . } [email protected] ic. ac. uk 6

GUI e. g. window panel 1 panel 2 button 1 button 3 button 2

GUI e. g. window panel 1 panel 2 button 1 button 3 button 2 button 4 7

Subtype Variance class Window<o> {. . . void render(Panel<? inside this> p) { List<this,

Subtype Variance class Window<o> {. . . void render(Panel<? inside this> p) { List<this, ? > all. Widgets =. . . ; . . . } Panel<window> <: Panel<? inside window> Panel<panel 1> <: Panel<? inside window> [email protected] ic. ac. uk 8

Subtype Variance • Already exists! – On Ownership and Accessibility (Lu and Potter, ECOOP

Subtype Variance • Already exists! – On Ownership and Accessibility (Lu and Potter, ECOOP 06) – any owner in universes (Müller, Dietl, . . . ) – ? in MOJO (Cameron, Drossopoulou, Noble, Smith, OOPSLA 07) –. . . [email protected] ic. ac. uk 9

Existential Types List<this, this> ncameron@doc. ic. ac. uk 10

Existential Types List<this, this> [email protected] ic. ac. uk 10

Existential Types List<this, this> List<? , ? > ncameron@doc. ic. ac. uk 11

Existential Types List<this, this> List<? , ? > [email protected] ic. ac. uk 11

Existential Types List<this, this> List<? , ? > o. List<o, o> ncameron@doc. ic. ac.

Existential Types List<this, this> List<? , ? > o. List<o, o> [email protected] ic. ac. uk 12

Owner Polymorphic Methods • Useful for iterators, etc. • Require existential types Expressible but

Owner Polymorphic Methods • Useful for iterators, etc. • Require existential types Expressible but not denotable types Similar problem to modelling wildcards - <sales. Pitch>e. g. , Wed 10: 00 am</sales. Pitch> [email protected] ic. ac. uk 13

Generics and Ownership class List<owner, dat> { Object<dat> datum; } List<o 1, o 2>

Generics and Ownership class List<owner, dat> { Object<dat> datum; } List<o 1, o 2> vs Class List<owner, X> { X datum; } List<o 1, Button<o 2>> [Potanin, Noble, Clarke, Biddle, OOPSLA 06] [email protected] ic. ac. uk 14

. . . and Existential Owners o. List<o, Button<this>> List<this, o. Button<o>> o. List<this,

. . . and Existential Owners o. List<o, Button<this>> List<this, o. Button<o>> o. List<this, Button<o>> o. List<o, Button<o>> List<this, o. List<that, Button<o>>> [email protected] ic. ac. uk 15

Benefits • Expressive and uniform • Easy to reason about • Well understood mechanism

Benefits • Expressive and uniform • Easy to reason about • Well understood mechanism – Existential types – Wildcards Todo • Encapsulation properties • Application/relation to other systems [email protected] ic. ac. uk 16

Thank You! ncameron@doc. ic. ac. uk 17

Thank You! [email protected] ic. ac. uk 17