Presentation is loading. Please wait.

Presentation is loading. Please wait.

Supervised by: Dr Sophia Drossopoulou, Dr Nobuko Yoshida Wildcards, Variance and Virtual Classes.

Similar presentations


Presentation on theme: "Supervised by: Dr Sophia Drossopoulou, Dr Nobuko Yoshida Wildcards, Variance and Virtual Classes."— Presentation transcript:

1 Supervised by: Dr Sophia Drossopoulou, Dr Nobuko Yoshida Wildcards, Variance and Virtual Classes Nicholas Cameron Transfer Talk

2 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Halfway Already… oParametric Polymorphism and Subtype Variance oJava Wildcards oGenerics and wildcards oProgramming with wildcards oFormalising wildcards oVirtual Classes oVirtual Types oVirtual Classes oTribe oParametric types

3 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Parametric Polymorphism * * Disclaimer: I don’t really write my shopping list in Excel.

4 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Parametric Polymorphism

5 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Parametric Polymorphism

6 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Parametric Polymorphism

7 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Parametric Polymorphism

8 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Generics class List { X get(int i)... void add(X x)... } List l = new List (); l.add(new Dog()); Dog d = l.get(0);

9 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Virtual Types class List { virtual type X; X get(int i)... void add(X x)... } class DogList extends List { X = Dog; }

10 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Invariance <: Dog <: Animal

11 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Invariance List

12 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Wildcards

13 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London ? o? May be used as an actual type argument oA list of some type (but we don’t know (or care) which type) void m(List aList)...

14 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Bounds oWildcards can have upper and lower bounds oub is a list of some type that is a subtype of Animal olb is a list of some type that is a supertype of Dog void m(List ub)... void m(List lb)...

15 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Subtype Variance List

16 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Subtype Variance oCovariance oContravariance List

17 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London The trade-off void m1(List l) { l.add(new Dog()); //type error Dog d = l.get(0); //ok } void m2(List l) { l.add(new Dog()); //ok Dog d = l.get(0); //type error }

18 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Wildcard Capture oNote: List List oBUT, we can pass it here oCapture conversion void m1(List x) {…} void m2 (List y) { this.m1(y); }

19 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Formalisation JJ

20 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London JJ oExistential types List =  X.List List =  Y  [Dog Object].List

21 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London JJ oCapture = open void m1(List x) {…} void m2 (  Y.List y) { open y as z:List in this. m1(z); }

22 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London JJ oSubtyping List

23 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Back to wildcard capture

24 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Wildcard Capture o...is not subtyping: void m1(List x1, List x2) {…} void m2 (List x1, List x2) { m1(x1, x2); //Type error! }

25 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Wildcard Capture o…requires existential types: void m1(Pair x) {…} Pair m2(List x) {…} void m3 (Pair xx, List x) { m1(xx); //Type error m1(m2(x)); //OK! }

26 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Wildcard Capture oxx:  Y,Z.Pair om2(x):  Y.Pair void m1(Pair x) {…} Pair m2(List x) {…} void m3 (Pair xx, List x) { m1(xx); //Type error m1(m2(x)); //OK! }

27 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Wildcard Capture om2(x):  Y.Pair void m1(Pair x) {…} Pair m2(List x) {…} void m3 (  Y.List x) { open x as y:List in this. m1(this. m2(y)); }

28 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Type System oExpressible but not denotable types oCaused by wildcard capture oSolved by using existential types oPack/close vs. subtyping oModelling capture oSoundness requirement

29 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Soundness

30 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Soundness oChallenges caused by: oType parameters in reduction of open expression oLower bounds oComplexity of formalism

31 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Lemmas ouBound*(lBound( X )) <: uBound*( X ) oC  subclassing oT <: R  T = R’ oWell formed type environments

32 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Wildcards – further work oFinish proofs oNearly done! oFormalise translation oImperative version

33 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Questions? Thank you! Report:

34 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Tribe

35 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Tribe oNested virtual classes class Graph { class Node { } class Edge { Node n1; Node n2; } class ColourGraph extends Graph { class Node { Colour c; }

36 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Tribe oPath dependent types this.out.Node n1.out.Node this.out.n1.out.Edge .Graph.Node class Graph { class Node { } class Edge { Node n1; Node n2; }

37 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Tribe oFlexible, powerful, elegant oUndecidable subtyping? oComplete subtyping?

38 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Tribe – further work oParametric polymorphism and variance oVirtual types? oExtend Tribe with virtual types oGenerics? oOrthogonal? oType variables in paths oGenericity over families

39 Wildcards, Variance and Virtual Classes Nick Cameron, Imperial College London Tribe – further work oDecidable fragment – T 9 oTribal Ownership oProgramming with virtual classes


Download ppt "Supervised by: Dr Sophia Drossopoulou, Dr Nobuko Yoshida Wildcards, Variance and Virtual Classes."

Similar presentations


Ads by Google