A Practical, Typed Variant Object Model
Or, How to Stand On Your Head and Enjoy the View
Pottayil Harisanker Menon, Zachary Palmer, Scott F. Smith, Alexander Rozenshteyn
The Johns Hopkins University
October 22, 2012
A Practical, Typed Variant Object Model Or, How to Stand On Your - - PowerPoint PPT Presentation
A Practical, Typed Variant Object Model Or, How to Stand On Your Head and Enjoy the View Pottayil Harisanker Menon, Zachary Palmer, Scott F. Smith, Alexander Rozenshteyn The Johns Hopkins University October 22, 2012 Object Encodings
Or, How to Stand On Your Head and Enjoy the View
Pottayil Harisanker Menon, Zachary Palmer, Scott F. Smith, Alexander Rozenshteyn
The Johns Hopkins University
October 22, 2012
Record-Based Encodings
Record-Based Encodings
Foundation for traditional OO languages
Record-Based Encodings
Foundation for traditional OO languages Easier to type
Record-Based Encodings
Foundation for traditional OO languages Easier to type Common [Cardelli ’84] [Cook ’89] . . .
Record-Based Encodings
Foundation for traditional OO languages Easier to type Common [Cardelli ’84] [Cook ’89] . . .
Variant-Based Encodings
Record-Based Encodings
Foundation for traditional OO languages Easier to type Common [Cardelli ’84] [Cook ’89] . . .
Variant-Based Encodings
Actor-based languages (Erlang)
Record-Based Encodings
Foundation for traditional OO languages Easier to type Common [Cardelli ’84] [Cook ’89] . . .
Variant-Based Encodings
Actor-based languages (Erlang) Harder to type
(Scala) (OCaml)
1 ♦❜❥❡❝t a { 2 } 1 ❧❡t a = { 2 }
(Scala) (OCaml)
1 ♦❜❥❡❝t a { 2
✈❛❧ v = 5
3 } 1 ❧❡t a = { 2
v = ref 5
3 }
Object fields are record fields
(Scala) (OCaml)
1 ♦❜❥❡❝t a { 2
✈❛❧ v = 5
3
❞❡❢ mth(x:Int)
4
:Int = { x+v }
5
❞❡❢ foo(x:Unit ){}
6 } 1 ❧❡t a = { 2
v = ref 5;
3
mth = ❢✉♥ self ->
4
❢✉♥ x -> x+! self.v;
5
foo = ❢✉♥ ✭✮ -> ✭✮
6 }
Object fields are record fields Methods are fields with functions
(Scala) (OCaml)
1 ♦❜❥❡❝t a { 2
✈❛❧ v = 5
3
❞❡❢ mth(x:Int)
4
:Int = { x+v }
5
❞❡❢ foo(x:Unit ){}
6 }; 7 a.mth (3) 1 ❧❡t a = { 2
v = ref 5;
3
mth = ❢✉♥ self ->
4
❢✉♥ x -> x+! self.v
5
foo = ❢✉♥ ✭✮ -> ✭✮
6 } ✐♥ 7 a.mth a 3
Object fields are record fields Methods are fields with functions Invocation projects methods
(Scala) (OCaml)
1 ♦❜❥❡❝t a { 2
✈❛❧ v = 5
3
❞❡❢ mth(x:Int)
4
:Int = { x+v }
5
❞❡❢ foo(x:Unit ){}
6 }; 7 a.mth (3) 1 ❧❡t a = { 2
v = ref 5;
3
mth = ❢✉♥ self ->
4
❢✉♥ x -> x+! self.v
5
foo = ❢✉♥ ✭✮ -> ✭✮
6 } ✐♥ 7 a.mth a 3
Object fields are record fields Methods are fields with functions Invocation projects methods
We ignore self-hiding for now.
(Scala) (OCaml)
1 ♦❜❥❡❝t a { 2 } 1 ❧❡t a = ❢✉♥ msg -> 2
♠❛t❝❤ msg ✇✐t❤
3
. . .
(Scala) (OCaml)
1 ♦❜❥❡❝t a { 2
✈❛❧ v = 5
3 } 1 ❧❡t v = ref 5 ✐♥ 2 ❧❡t a = ❢✉♥ msg -> 3
♠❛t❝❤ msg ✇✐t❤
4
. . .
Fields by closure
(Scala) (OCaml)
1 ♦❜❥❡❝t a { 2
✈❛❧ v = 5
3
❞❡❢ mth(x:Int)
4
:Int = { x+v }
5
❞❡❢ foo(x:Unit ){}
6 } 1 ❧❡t v = ref 5 ✐♥ 2 ❧❡t a = ❢✉♥ msg -> 3
♠❛t❝❤ msg ✇✐t❤
4
| ‘mth (self ,x) ->
5
x+! self.v
6
| ‘foo ✭✮ -> ✭✮
Fields by closure Methods are other message handlers
(Scala) (OCaml)
1 ♦❜❥❡❝t a { 2
✈❛❧ v = 5
3
❞❡❢ mth(x:Int)
4
:Int = { x+v }
5
❞❡❢ foo(x:Unit ){}
6 }; 7 a.mth (3) 1 ❧❡t v = ref 5 ✐♥ 2 ❧❡t a = ❢✉♥ msg -> 3
♠❛t❝❤ msg ✇✐t❤
4
| ‘mth (self ,x) ->
5
x+! self.v
6
| ‘foo ✭✮ -> ✭✮
7 ✐♥ a (‘mth (a ,3))
Fields by closure Methods are other message handlers Invocation is just message passing
(Scala) (OCaml)
1 ♦❜❥❡❝t a { 2
✈❛❧ v = 5
3
❞❡❢ mth(x:Int)
4
:Int = { x+v }
5
❞❡❢ foo(x:Unit ){}
6 }; 7 a.mth (3) 1 ❧❡t v = ref 5 ✐♥ 2 ❧❡t a = ❢✉♥ msg -> 3
♠❛t❝❤ msg ✇✐t❤
4
| ‘mth (self ,x) ->
5
x+! self.v
6
| ‘foo ✭✮ -> ✭✮
7 ✐♥ a (‘mth (a ,3))
Fields by closure Methods are other message handlers Invocation is just message passing But this doesn’t typecheck!
1 ♠❛t❝❤ v ✇✐t❤ 2
| ‘Odd y -> y mod 2 = 1
3
| ‘Dbl x -> x + x
Typechecking variant destruction is tricky
1 ♠❛t❝❤ v ✇✐t❤ 2
| ‘Odd y -> y mod 2 = 1
3
| ‘Dbl x -> x + x
Typechecking variant destruction is tricky Most languages (e.g. Caml) fail on unification
1 ♠❛t❝❤ v ✇✐t❤ 2
| ‘Odd y -> y mod 2 = 1
3
| ‘Dbl x -> x + x
Typechecking variant destruction is tricky Most languages (e.g. Caml) fail on unification Union types
1 ♠❛t❝❤ ‘Dbl 2 ✇✐t❤ 2
| ‘Odd y -> y mod 2 = 1
3
| ‘Dbl x -> x + x
Typechecking variant destruction is tricky Most languages (e.g. Caml) fail on unification Union types are insufficient!
1 ♠❛t❝❤ ‘Dbl 2 ✇✐t❤ 2
| ‘Odd y -> y mod 2 = 1
3
| ‘Dbl x -> x + x
Typechecking variant destruction is tricky Most languages (e.g. Caml) fail on unification Union types are insufficient! Record construction is heterogeneously typed
1 ♠❛t❝❤ ‘Dbl 2 ✇✐t❤ 2
| ‘Odd y -> y mod 2 = 1
3
| ‘Dbl x -> x + x
Typechecking variant destruction is tricky Most languages (e.g. Caml) fail on unification Union types are insufficient! Record construction is heterogeneously typed Variant destruction is not
Our objective: a purely type-inferred variant-based
Our objective: a purely type-inferred variant-based
This can work! We just need...
Our objective: a purely type-inferred variant-based
This can work! We just need... A couple new expression forms Weakly dependent types Precise polymorphism A whole-program typechecking pass
Our objective: a purely type-inferred variant-based
This can work! We just need... A couple new expression forms Weakly dependent types Precise polymorphism A whole-program typechecking pass ...and then we reap the benefits!
(Extensible, type-indexed records)
(Extensible, type-indexed records)
(Functions with built-in patterns)
(Extensible, type-indexed records)
(Functions with built-in patterns)
TinyBang
1
❵❞❜❧ x -> x + x
Methods are scapes
TinyBang
1
❵❞❜❧ x -> x + x
Methods are scapes: functions with patterns
TinyBang
1 (❵❞❜❧ x -> x + x) ❵❞❜❧ 3
Methods are scapes: functions with patterns Invoke methods by passing messages
TinyBang
1 (❵❞❜❧ x -> x + x) ❵❞❜❧ 3
Methods are scapes: functions with patterns Invoke methods by passing first-class messages
TinyBang
1 (❵❞❜❧ x -> x + x) ❵❞❜❧ 3
Methods are scapes: functions with patterns Invoke methods by passing first-class messages (just labeled data)
1
❵❞❜❧ x -> x + x
1
(❵❞❜❧ x -> x + x) &
2
(❵♦❞❞ y -> y ♠♦❞ 2 == 1)
Scapes are combined by onioning
1 ((❵❞❜❧ x -> x + x) & 2
(❵♦❞❞ y -> y ♠♦❞ 2 == 1)) (❵❞❜❧ 2)
Scapes are combined by onioning Application finds match
1 ((❵❞❜❧ x -> x + x) & 2
(❵♦❞❞ y -> y ♠♦❞ 2 == 1)) (❵❞❜❧ 2)
1 ♦❜❥❡❝t a { 2
❞❡❢ dbl(x:Int):Int = { x + x }
3
❞❡❢ pos(y:Int): Boolean = { y % 2 == 1 }
4 } 5 a.dbl (2)
1 ((❵❞❜❧ x -> x + x) & 2
(❵♦❞❞ y -> y ♠♦❞ 2 == 1)) (❵❞❜❧ 2)
Scapes are combined by onioning Application finds rightmost match (asymmetric)
1 ((❵❞❜❧ x -> x + x) & 2
(❵♦❞❞ y -> y ♠♦❞ 2 == 1)) (❵❞❜❧ 2)
Scapes are combined by onioning Application finds rightmost match (asymmetric) Subsumes case expressions
1 ((❵❞❜❧ x -> x + x) & 2
(❵♦❞❞ y -> y ♠♦❞ 2 == 1)) (❵❞❜❧ 2)
Scapes are combined by onioning Application finds rightmost match (asymmetric) Subsumes case expressions Generalizes First-Class Cases [Blume et. al. ’06]
1
(❵❞❜❧ x -> x + x) &
2
(❵♦❞❞ y -> y ♠♦❞ 2 == 1) (❵❞❜❧ ✐♥t ∪ ❵♦❞❞ ✐♥t) -> (✐♥t ∪ ❜♦♦❧)
Simple union type loses alignment
1
(❵❞❜❧ x -> x + x) &
2
(❵♦❞❞ y -> y ♠♦❞ 2 == 1) (❵❞❜❧ ✐♥t -> ✐♥t) & (❵♦❞❞ ✐♥t -> ❜♦♦❧)
Simple union type loses alignment Onion type does not
1
(❵❞❜❧ x -> x + x) &
2
(❵♦❞❞ y -> y ♠♦❞ 2 == 1) (❵❞❜❧ ✐♥t -> ✐♥t) & (❵♦❞❞ ✐♥t -> ❜♦♦❧)
Simple union type loses alignment Onion type does not Weakly dependent type
1
(❵❞❜❧ x -> x + x) &
2
(❵♦❞❞ y -> y ♠♦❞ 2 == 1) (❵❞❜❧ ✐♥t -> ✐♥t) & (❵♦❞❞ ✐♥t -> ❜♦♦❧)
Simple union type loses alignment Onion type does not Weakly dependent type Relies heavily on polymorphism
Pure variant model: get/set messages
1
(❵❞❜❧ x -> x + x) &
2
(❵♦❞❞ y -> y ♠♦❞ 2 == 1) &
3
❵❩ 5
Pure variant model: get/set messages Hybrid model: variant methods, record fields
1
(❵❞❜❧ x -> x + x) &
2
(❵♦❞❞ y -> y ♠♦❞ 2 == 1) &
3
❵❩ 5
Pure variant model: get/set messages Hybrid model: variant methods, record fields Similar to type-indexed rows [Shields, Meijer ’01]
1
(❵❞❜❧ x -> x + x) &
2
(❵♦❞❞ y -> y ♠♦❞ 2 == 1) &
3
❵❩ 5
Pure variant model: get/set messages Hybrid model: variant methods, record fields Similar to type-indexed rows [Shields, Meijer ’01] Labels implicitly create cells
1 ❞❡❢ o = (❵❞❜❧ x -> x + x) & 2
(❵♦❞❞ y -> y ♠♦❞ 2 == 1) &
3
❵❩ 5
4 ✐♥ o.❩
Pure variant model: get/set messages Hybrid model: variant methods, record fields Similar to type-indexed rows [Shields, Meijer ’01] Labels implicitly create cells Field access by projection
1 ❞❡❢ o = (❵❞❜❧ x -> x + x) & 2
(❵♦❞❞ y -> y ♠♦❞ 2 == 1) &
3
❵❩ 5
4 ✐♥ (❵❩ z -> z) o
Pure variant model: get/set messages Hybrid model: variant methods, record fields Similar to type-indexed rows [Shields, Meijer ’01] Labels implicitly create cells Field access by projection/pattern match
1 ❞❡❢ o = (❵❞❜❧ x -> x + x) & 2
(❵♦❞❞ y -> y ♠♦❞ 2 == 1) &
3
❵❩ 5
4 ✐♥ (❵❩ z -> z) o
Pure variant model: get/set messages Hybrid model: variant methods, record fields Similar to type-indexed rows [Shields, Meijer ’01] Labels implicitly create cells Field access by projection/pattern match But what about self?
1 ❞❡❢ ticker = 2
❵① 0 &
3
(❵✐♥❝ _ ->
4
s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)
5 ✐♥ ticker ❵✐♥❝ ✭✮
❵s❡❧❢ ❵s❡❧❢
1 ❞❡❢ ticker = 2
❵① 0 &
3
(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->
4
s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)
5 ✐♥ ticker ❵✐♥❝ ✭✮
Add ❵s❡❧❢ to all parameters
❵s❡❧❢
1 ❞❡❢ ticker = 2
❵① 0 &
3
(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->
4
s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)
5 ✐♥ ticker ❵✐♥❝ ✭✮
Add ❵s❡❧❢ to all parameters
& is pattern conjunction ❵s❡❧❢
1 ❞❡❢ ticker = 2
❵① 0 &
3
(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->
4
s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)
5 ✐♥ ticker (❵✐♥❝ ✭✮ & ❵s❡❧❢ ticker)
Add ❵s❡❧❢ to all parameters
& is pattern conjunction
Add ❵s❡❧❢ to all call sites
1 ❞❡❢ ticker = 2
❵① 0 &
3
(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->
4
s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)
5 ✐♥ ticker (❵✐♥❝ ✭✮ & ❵s❡❧❢ ticker)
Add ❵s❡❧❢ to all parameters
& is pattern conjunction
Add ❵s❡❧❢ to all call sites Be happy?
1 ❞❡❢ obj = 2
✐❢ something t❤❡♥
3
(❵❢♦♦ _ & ❵s❡❧❢ s -> s ❵❜❛r ✭✮) &
4
(❵❜❛r _ -> 1)
5
❡❧s❡
6
(❵❢♦♦ _ & ❵s❡❧❢ s -> s ❵❜❛③ ✭✮) &
7
(❵❜❛③ _ -> 2)
8 ✐♥ obj ❵❢♦♦ ✭✮
αSelf =
(❵❢♦♦ _ & ❵s❡❧❢ α1 -> ✐♥t) & (❵❜❛r _ -> ✐♥t) where α1 has ❵❜❛r
(❵❜❛③ _ -> ✐♥t) where α2 has ❵❜❛③
αSelf <:
(❵❢♦♦ _ & ❵s❡❧❢ α1 -> ✐♥t) & (❵❜❛r _ -> ✐♥t) where α1 has ❵❜❛r
αSelf <:
(❵❢♦♦ _ & ❵s❡❧❢ α2 -> ✐♥t) & (❵❜❛③ _ -> ✐♥t) where α2 has ❵❜❛③
Classic object encodings [Bruce et. al. ’98]
Classic object encodings [Bruce et. al. ’98]
Type of self is fixed at instantiation
Classic object encodings [Bruce et. al. ’98]
Type of self is fixed at instantiation No object extensibility
Classic object encodings [Bruce et. al. ’98]
Type of self is fixed at instantiation No object extensibility
Extensible Object Calculus [Fisher et. al. ’98]
Classic object encodings [Bruce et. al. ’98]
Type of self is fixed at instantiation No object extensibility
Extensible Object Calculus [Fisher et. al. ’98]
Prototype objects: extensible but not callable
Classic object encodings [Bruce et. al. ’98]
Type of self is fixed at instantiation No object extensibility
Extensible Object Calculus [Fisher et. al. ’98]
Prototype objects: extensible but not callable Proper objects: callable but not extensible
Classic object encodings [Bruce et. al. ’98]
Type of self is fixed at instantiation No object extensibility
Extensible Object Calculus [Fisher et. al. ’98]
Prototype objects: extensible but not callable Proper objects: callable but not extensible Prototypes can be sealed into proper objects
Classic object encodings [Bruce et. al. ’98]
Type of self is fixed at instantiation No object extensibility
Extensible Object Calculus [Fisher et. al. ’98]
Prototype objects: extensible but not callable Proper objects: callable but not extensible Prototypes can be sealed into proper objects Sealing is permanent
Classic object encodings [Bruce et. al. ’98]
Type of self is fixed at instantiation No object extensibility
Extensible Object Calculus [Fisher et. al. ’98]
Prototype objects: extensible but not callable Proper objects: callable but not extensible Prototypes can be sealed into proper objects Sealing is permanent Sealing is meta-theoretic
Classic object encodings [Bruce et. al. ’98]
Type of self is fixed at instantiation No object extensibility
Extensible Object Calculus [Fisher et. al. ’98]
Prototype objects: extensible but not callable Proper objects: callable but not extensible Prototypes can be sealed into proper objects Sealing is permanent Sealing is meta-theoretic
TinyBang
Classic object encodings [Bruce et. al. ’98]
Type of self is fixed at instantiation No object extensibility
Extensible Object Calculus [Fisher et. al. ’98]
Prototype objects: extensible but not callable Proper objects: callable but not extensible Prototypes can be sealed into proper objects Sealing is permanent Sealing is meta-theoretic
TinyBang
Sealing is encodable (no meta-theory)
Classic object encodings [Bruce et. al. ’98]
Type of self is fixed at instantiation No object extensibility
Extensible Object Calculus [Fisher et. al. ’98]
Prototype objects: extensible but not callable Proper objects: callable but not extensible Prototypes can be sealed into proper objects Sealing is permanent Sealing is meta-theoretic
TinyBang
Sealing is encodable (no meta-theory) Sealed objects can be extended and resealed
1 ❞❡❢ r❡❝ seal = obj -> 2
3
(msg -> obj (❵s❡❧❢ (seal obj) & msg)) ✐♥
4 ❞❡❢ point = 5
❵① 2 & ❵② 4 &
6
(❵❧✶ _ & ❵s❡❧❢ s❡❧❢ -> s❡❧❢.① + s❡❧❢.②) ✐♥
7 ❞❡❢ sealedPoint = seal point ✐♥ 8 sealedPoint ❵❧✶ ✭✮ 9 . . .
1 . . . 2 ❞❡❢ obj = seal ( 3
❵① 0 &
4
(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->
5
s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)) ✐♥
6 obj ❵✐♥❝ ✭✮; obj ❵✐♥❝ ✭✮; 7 ❞❡❢ extobj = seal ( 8
9
(❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ ->
10
s❡❧❢.① = s❡❧❢.① + s❡❧❢.① ✐♥ s❡❧❢.①)) ✐♥
11 extobj ❵❞❜❧ ✭✮; extobj ❵✐♥❝ ✭✮
1 . . . 2 ❞❡❢ obj = seal ( 3
❵① 0 &
4
(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->
5
s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)) ✐♥
6 obj ❵✐♥❝ ✭✮; obj ❵✐♥❝ ✭✮; 7 ❞❡❢ extobj = seal ( 8
9
(❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ ->
10
s❡❧❢.① = s❡❧❢.① + s❡❧❢.① ✐♥ s❡❧❢.①)) ✐♥
11 extobj ❵❞❜❧ ✭✮; extobj ❵✐♥❝ ✭✮
1 . . . 2 ❞❡❢ obj = seal ( 3
❵① 0 &
4
(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->
5
s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)) ✐♥
6 obj ❵✐♥❝ ✭✮; obj ❵✐♥❝ ✭✮; 7 ❞❡❢ extobj = seal ( 8
9
(❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ ->
10
s❡❧❢.① = s❡❧❢.① + s❡❧❢.① ✐♥ s❡❧❢.①)) ✐♥
11 extobj ❵❞❜❧ ✭✮; extobj ❵✐♥❝ ✭✮
1 . . . 2 ❞❡❢ obj = seal ( 3
❵① 0 &
4
(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->
5
s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)) ✐♥
6 obj ❵✐♥❝ ✭✮; obj ❵✐♥❝ ✭✮; 7 ❞❡❢ extobj = seal ( 8
9
(❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ ->
10
s❡❧❢.① = s❡❧❢.① + s❡❧❢.① ✐♥ s❡❧❢.①)) ✐♥
11 extobj ❵❞❜❧ ✭✮; extobj ❵✐♥❝ ✭✮
1 . . . 2 ❞❡❢ obj = seal ( 3
❵① 0 &
4
(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->
5
s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)) ✐♥
6 obj ❵✐♥❝ ✭✮; obj ❵✐♥❝ ✭✮; 7 ❞❡❢ extobj = seal ( 8
9
(❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ ->
10
s❡❧❢.① = s❡❧❢.① + s❡❧❢.① ✐♥ s❡❧❢.①)) ✐♥
11 extobj ❵❞❜❧ ✭✮; extobj ❵✐♥❝ ✭✮
1 . . . 2 ❞❡❢ obj = seal (. . .) ✐♥ 3 obj ❵✐♥❝ ✭✮; obj ❵✐♥❝ ✭✮; 4 ❞❡❢ extobj = seal (. . .) ✐♥ 5 extobj ❵❞❜❧ ✭✮; extobj ❵✐♥❝ ✭✮
1 . . . 2 ❞❡❢ obj = seal (. . .) ✐♥ 3 obj ❵✐♥❝ ✭✮; obj ❵✐♥❝ ✭✮; 4 ❞❡❢ extobj = seal (. . .) ✐♥ 5 extobj ❵❞❜❧ ✭✮; extobj ❵✐♥❝ ✭✮
❵✐♥❝ ✭✮
1 . . . 2 ❞❡❢ obj = seal (. . .) ✐♥ 3 obj ❵✐♥❝ ✭✮; obj ❵✐♥❝ ✭✮; 4 ❞❡❢ extobj = seal (. . .) ✐♥ 5 extobj ❵❞❜❧ ✭✮; extobj ❵✐♥❝ ✭✮
❵s❡❧❢ extobj & ❵✐♥❝ ✭✮
1 . . . 2 ❞❡❢ obj = seal (. . .) ✐♥ 3 obj ❵✐♥❝ ✭✮; obj ❵✐♥❝ ✭✮; 4 ❞❡❢ extobj = seal (. . .) ✐♥ 5 extobj ❵❞❜❧ ✭✮; extobj ❵✐♥❝ ✭✮
❵s❡❧❢ obj & ❵s❡❧❢ extobj & ❵✐♥❝ ✭✮
1 . . . 2 ❞❡❢ obj = seal (. . .) ✐♥ 3 obj ❵✐♥❝ ✭✮; obj ❵✐♥❝ ✭✮; 4 ❞❡❢ extobj = seal (. . .) ✐♥ 5 extobj ❵❞❜❧ ✭✮; extobj ❵✐♥❝ ✭✮
❵s❡❧❢ obj & ❵s❡❧❢ extobj & ❵✐♥❝ ✭✮
1 ❞❡❢ point = seal (❵① 0 & ❵② 0 & 2
(❵❧✶ _ & ❵s❡❧❢ s❡❧❢ ->
3
s❡❧❢.① + s❡❧❢.②)) ✐♥
4 ❞❡❢ mixin = (❵♥❡❛r❩❡r♦ _ & ❵s❡❧❢ s❡❧❢ -> 5
(s❡❧❢ ❵❧✶ ✭✮) <= 4) ✐♥
6 ❞❡❢ mixedPoint = seal (point & mixin) ✐♥ 7 mixedPoint ❵♥❡❛r❩❡r♦ ✭✮
Mixins
1 ❞❡❢ point =
. . . ✐♥
2 ❞❡❢ mixin = ((❵♥❡❛r❩❡r♦ _ & ❵s❡❧❢ s❡❧❢ -> 3
(s❡❧❢ ❵❧✶ ✭✮) <= 4)) ✐♥
4 ❞❡❢ mixedPoint = seal (point & mixin) ✐♥ 5 mixedPoint ❵♥❡❛r❩❡r♦ ✭✮
Mixins Higher-order object extension
1 ❞❡❢ obj = seal ( 2
❵① 0 & (❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->
3
s❡❧❢.① = s❡❧❢.① + 1 ✐♥ s❡❧❢.①)) ✐♥
4 ❞❡❢ obj2 = seal ( 5
(obj &. ❵①) & ❵② 0 &
6
(❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ ->
7
s❡❧❢.② = s❡❧❢.② + s❡❧❢.① ✐♥ s❡❧❢.②)) ✐♥
8 . . .
Mixins Higher-order object extension Data sharing
1 ❞❡❢ obj = seal ( 2
❵① 0 &
3
(❵✐♥❝ n:✐♥t & ❵s❡❧❢ s❡❧❢ ->
4
s❡❧❢.① = s❡❧❢.① + n ✐♥ s❡❧❢.①) &
5
(❵✐♥❝ n:✉♥✐t & ❵s❡❧❢ s❡❧❢ ->
6
s❡❧❢ ❵✐♥❝ 1) ✐♥
7 obj (❵✐♥❝ ✭✮); obj (❵✐♥❝ 4)
Mixins Higher-order object extension Data sharing Overloading
Mixins Higher-order object extension Data sharing Overloading Classes, inheritance, etc.
Subtype constraint system
Subtype constraint system Assign each subexpression a type variable
Subtype constraint system Assign each subexpression a type variable Derive initial constraint set over expression
Subtype constraint system Assign each subexpression a type variable Derive initial constraint set over expression Perform knowledge closure on constraints
Subtype constraint system Assign each subexpression a type variable Derive initial constraint set over expression Perform knowledge closure on constraints Check resulting closure for consistency
Subtype constraint system Assign each subexpression a type variable Derive initial constraint set over expression Perform knowledge closure on constraints Check resulting closure for consistency Soundness is proven over inference system
5 + 3
5 + 3
α1 α2
5 + 3
α1 α2 α3
5 + 3
int α1 α2 α3
5 + 3
int α1 α2 α3
5 + 3
int α1 α2 α3 +
5 + 3
int α1 α2 α3 +
5 + 3
int α1 α2 α3 +
5 + 3
int α1 α2 α3 +
5 + 3
int α1 α2 α3 +
5 + 3
int α1 α2 α3 +
5 + 3
int α1 α2 α3 +
x -> x + x
x -> x + x
+
x -> x + x
+
x -> x + x
+
x -> x + x
+
x -> x + x
(x -> x + x) 5
❼
(x -> x + x) 5
❼
(x -> x + x) 5
❼
(x -> x + x) 5
❼
(x -> x + x) 5
❼ +
(x -> x + x) 5
❼ +
(x -> x + x) 5
❼ +
(x -> x + x) 5
❼ +
(x -> x + x) 5
❼ +
(x -> x + x) 5
❼ +
(x -> x + x) 5
❼ +
(x -> x + x) 5
❼ +
(x -> x + x) 5
❼ +
(x -> x + x) 5
❼ +
(x -> x + x) 5 :
❼ +
Let-bound polymorphism
Let-bound polymorphism
Type-parametric methods fail
Let-bound polymorphism
Type-parametric methods fail
Local polymorphism
Let-bound polymorphism
Type-parametric methods fail
Local polymorphism
Objects are not local
Let-bound polymorphism
Type-parametric methods fail
Local polymorphism
Objects are not local Requires type annotations
Let-bound polymorphism
Type-parametric methods fail
Local polymorphism
Objects are not local Requires type annotations
TinyBang uses call-site polymorphism
Let-bound polymorphism
Type-parametric methods fail
Local polymorphism
Objects are not local Requires type annotations
TinyBang uses call-site polymorphism
Each call site is freshly polyinstantiated
Let-bound polymorphism
Type-parametric methods fail
Local polymorphism
Objects are not local Requires type annotations
TinyBang uses call-site polymorphism
Each call site is freshly polyinstantiated Recursion reuses variable contours
❞❡❢ id = x -> x ✐♥ (id ✭✮ & id 1)
❼ ❼
❞❡❢ id = x -> x ✐♥ (id ✭✮ & id 1)
❼ ❼
❞❡❢ id = x -> x ✐♥ (id ✭✮ & id 1)
❼ ❼ &
❞❡❢ id = x -> x ✐♥ (id ✭✮ & id 1)
❼ ❼ &
❞❡❢ id = x -> x ✐♥ (id ✭✮ & id 1)
❼ ❼ &
Aims to infer types for script-like programs
Aims to infer types for script-like programs Uses type information for better performance
Aims to infer types for script-like programs Uses type information for better performance Desugars down to TinyBang
Aims to infer types for script-like programs Uses type information for better performance Desugars down to TinyBang Provides syntax for classes, modules, etc.
Aims to infer types for script-like programs Uses type information for better performance Desugars down to TinyBang Provides syntax for classes, modules, etc. Enough polymorphism for scripting intuitions
Aims to infer types for script-like programs Uses type information for better performance Desugars down to TinyBang Provides syntax for classes, modules, etc. Enough polymorphism for scripting intuitions ...without divergence or exponential blow-up
TinyBang encodes objects as scapes and onions
TinyBang encodes objects as scapes and onions Variant destruction is heterogeneously typed
TinyBang encodes objects as scapes and onions Variant destruction is heterogeneously typed (Re)sealing is encodable as a function
TinyBang encodes objects as scapes and onions Variant destruction is heterogeneously typed (Re)sealing is encodable as a function Flexible OO structures are encodable
TinyBang encodes objects as scapes and onions Variant destruction is heterogeneously typed (Re)sealing is encodable as a function Flexible OO structures are encodable Heavily uses call-site polymorphism model
TinyBang encodes objects as scapes and onions Variant destruction is heterogeneously typed (Re)sealing is encodable as a function Flexible OO structures are encodable Heavily uses call-site polymorphism model Requires whole-program typechecking
TinyBang encodes objects as scapes and onions Variant destruction is heterogeneously typed (Re)sealing is encodable as a function Flexible OO structures are encodable Heavily uses call-site polymorphism model Requires whole-program typechecking