Typing the Onion ( ❵❞❜❧ x -> x + x) & 1 ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) 2 ( ❵❞❜❧ ✐♥t ∪ ❵♦❞❞ ✐♥t ) -> ( ✐♥t ∪ ❜♦♦❧ ) Simple union type loses alignment
Typing the Onion ( ❵❞❜❧ x -> x + x) & 1 ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) 2 ( ❵❞❜❧ ✐♥t -> ✐♥t ) & ( ❵♦❞❞ ✐♥t -> ❜♦♦❧ ) Simple union type loses alignment Onion type does not
Typing the Onion ( ❵❞❜❧ x -> x + x) & 1 ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) 2 ( ❵❞❜❧ ✐♥t -> ✐♥t ) & ( ❵♦❞❞ ✐♥t -> ❜♦♦❧ ) Simple union type loses alignment Onion type does not Weakly dependent type
Typing the Onion ( ❵❞❜❧ x -> x + x) & 1 ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) 2 ( ❵❞❜❧ ✐♥t -> ✐♥t ) & ( ❵♦❞❞ ✐♥t -> ❜♦♦❧ ) Simple union type loses alignment Onion type does not Weakly dependent type Relies heavily on polymorphism
Fields Pure variant model: get/set messages
Fields ( ❵❞❜❧ x -> x + x) & 1 ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) & 2 ❵❩ 5 3 Pure variant model: get/set messages Hybrid model: variant methods, record fields
Fields ( ❵❞❜❧ x -> x + x) & 1 ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) & 2 ❵❩ 5 3 Pure variant model: get/set messages Hybrid model: variant methods, record fields Similar to type-indexed rows [Shields, Meijer ’01]
Fields ( ❵❞❜❧ x -> x + x) & 1 ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) & 2 ❵❩ 5 3 Pure variant model: get/set messages Hybrid model: variant methods, record fields Similar to type-indexed rows [Shields, Meijer ’01] Labels implicitly create cells
Fields 1 ❞❡❢ o = ( ❵❞❜❧ x -> x + x) & ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) & 2 ❵❩ 5 3 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
Fields 1 ❞❡❢ o = ( ❵❞❜❧ x -> x + x) & ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) & 2 ❵❩ 5 3 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
Fields 1 ❞❡❢ o = ( ❵❞❜❧ x -> x + x) & ( ❵♦❞❞ y -> y ♠♦❞ 2 == 1) & 2 ❵❩ 5 3 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?
❵s❡❧❢ ❵s❡❧❢ Na¨ ıve Self 1 ❞❡❢ ticker = ❵① 0 & 2 ( ❵✐♥❝ _ -> 3 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① ) 4 5 ✐♥ ticker ❵✐♥❝ ✭✮
❵s❡❧❢ Na¨ ıve Self 1 ❞❡❢ ticker = ❵① 0 & 2 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 3 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① ) 4 5 ✐♥ ticker ❵✐♥❝ ✭✮ Add ❵s❡❧❢ to all parameters
❵s❡❧❢ Na¨ ıve Self 1 ❞❡❢ ticker = ❵① 0 & 2 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 3 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① ) 4 5 ✐♥ ticker ❵✐♥❝ ✭✮ Add ❵s❡❧❢ to all parameters & is pattern conjunction
Na¨ ıve Self 1 ❞❡❢ ticker = ❵① 0 & 2 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 3 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① ) 4 5 ✐♥ ticker ( ❵✐♥❝ ✭✮ & ❵s❡❧❢ ticker) Add ❵s❡❧❢ to all parameters & is pattern conjunction Add ❵s❡❧❢ to all call sites
Na¨ ıve Self 1 ❞❡❢ ticker = ❵① 0 & 2 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 3 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① ) 4 5 ✐♥ ticker ( ❵✐♥❝ ✭✮ & ❵s❡❧❢ ticker) Add ❵s❡❧❢ to all parameters & is pattern conjunction Add ❵s❡❧❢ to all call sites Be happy?
Na¨ ıve Self: Type Problems 1 ❞❡❢ obj = ✐❢ something t❤❡♥ 2 ( ❵❢♦♦ _ & ❵s❡❧❢ s -> s ❵❜❛r ✭✮ ) & 3 ( ❵❜❛r _ -> 1) 4 ❡❧s❡ 5 ( ❵❢♦♦ _ & ❵s❡❧❢ s -> s ❵❜❛③ ✭✮ ) & 6 ( ❵❜❛③ _ -> 2) 7 8 ✐♥ obj ❵❢♦♦ ✭✮
Na¨ ıve Self: Problems α Self = ( ❵❢♦♦ _ & ❵s❡❧❢ α 1 -> ✐♥t ) & ( ❵❜❛r _ -> ✐♥t ) where α 1 has ❵❜❛r � ( ❵❢♦♦ _ & ❵s❡❧❢ α 2 -> ✐♥t ) & ( ❵❜❛③ _ -> ✐♥t ) where α 2 has ❵❜❛③
Na¨ ıve Self: Problems ( ❵❢♦♦ _ & ❵s❡❧❢ α 1 -> ✐♥t ) & < : ( ❵❜❛r _ -> ✐♥t ) α Self where α 1 has ❵❜❛r ( ❵❢♦♦ _ & ❵s❡❧❢ α 2 -> ✐♥t ) & < : ( ❵❜❛③ _ -> ✐♥t ) α Self where α 2 has ❵❜❛③
Self Solutions Classic object encodings [Bruce et. al. ’98]
Self Solutions Classic object encodings [Bruce et. al. ’98] Type of self is fixed at instantiation
Self Solutions Classic object encodings [Bruce et. al. ’98] Type of self is fixed at instantiation No object extensibility
Self Solutions Classic object encodings [Bruce et. al. ’98] Type of self is fixed at instantiation No object extensibility Extensible Object Calculus [Fisher et. al. ’98]
Self Solutions 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
Self Solutions 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
Self Solutions 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
Self Solutions 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
Self Solutions 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
Self Solutions 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
Self Solutions 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)
Self Solutions 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
Sealing in TinyBang 1 ❞❡❢ r❡❝ seal = obj -> obj & 2 (msg -> obj ( ❵s❡❧❢ (seal obj) & msg)) ✐♥ 3 4 ❞❡❢ point = ❵① 2 & ❵② 4 & 5 ( ❵❧✶ _ & ❵s❡❧❢ s❡❧❢ -> s❡❧❢ . ① + s❡❧❢ . ② ) ✐♥ 6 7 ❞❡❢ sealedPoint = seal point ✐♥ 8 sealedPoint ❵❧✶ ✭✮ 9 . . .
Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( ❵① 0 & 3 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 4 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① )) ✐♥ 5 6 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 7 ❞❡❢ extobj = seal ( obj & 8 ( ❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ -> 9 s❡❧❢ . ① = s❡❧❢ . ① + s❡❧❢ . ① ✐♥ s❡❧❢ . ① )) ✐♥ 10 11 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮ x =0
Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( ❵① 0 & 3 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 4 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① )) ✐♥ 5 6 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 7 ❞❡❢ extobj = seal ( obj & 8 ( ❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ -> 9 s❡❧❢ . ① = s❡❧❢ . ① + s❡❧❢ . ① ✐♥ s❡❧❢ . ① )) ✐♥ 10 11 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮ x =1
Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( ❵① 0 & 3 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 4 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① )) ✐♥ 5 6 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 7 ❞❡❢ extobj = seal ( obj & 8 ( ❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ -> 9 s❡❧❢ . ① = s❡❧❢ . ① + s❡❧❢ . ① ✐♥ s❡❧❢ . ① )) ✐♥ 10 11 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮ x =2
Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( ❵① 0 & 3 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 4 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① )) ✐♥ 5 6 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 7 ❞❡❢ extobj = seal ( obj & 8 ( ❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ -> 9 s❡❧❢ . ① = s❡❧❢ . ① + s❡❧❢ . ① ✐♥ s❡❧❢ . ① )) ✐♥ 10 11 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮ x =4
Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( ❵① 0 & 3 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 4 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① )) ✐♥ 5 6 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 7 ❞❡❢ extobj = seal ( obj & 8 ( ❵❞❜❧ _ & ❵s❡❧❢ s❡❧❢ -> 9 s❡❧❢ . ① = s❡❧❢ . ① + s❡❧❢ . ① ✐♥ s❡❧❢ . ① )) ✐♥ 10 11 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮ x =5
Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( . . . ) ✐♥ 3 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 4 ❞❡❢ extobj = seal ( . . . ) ✐♥ 5 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮
Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( . . . ) ✐♥ 3 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 4 ❞❡❢ extobj = seal ( . . . ) ✐♥ 5 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮ ❵✐♥❝ ✭✮
Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( . . . ) ✐♥ 3 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 4 ❞❡❢ extobj = seal ( . . . ) ✐♥ 5 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮ ❵s❡❧❢ extobj & ❵✐♥❝ ✭✮
Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( . . . ) ✐♥ 3 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 4 ❞❡❢ extobj = seal ( . . . ) ✐♥ 5 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮ ❵s❡❧❢ obj & ❵s❡❧❢ extobj & ❵✐♥❝ ✭✮
Resealing Objects 1 . . . 2 ❞❡❢ obj = seal ( . . . ) ✐♥ 3 obj ❵✐♥❝ ✭✮ ; obj ❵✐♥❝ ✭✮ ; 4 ❞❡❢ extobj = seal ( . . . ) ✐♥ 5 extobj ❵❞❜❧ ✭✮ ; extobj ❵✐♥❝ ✭✮ ❵s❡❧❢ obj & ❵s❡❧❢ extobj & ❵✐♥❝ ✭✮
Other Features 1 ❞❡❢ point = seal ( ❵① 0 & ❵② 0 & ( ❵❧✶ _ & ❵s❡❧❢ s❡❧❢ -> 2 s❡❧❢ . ① + s❡❧❢ . ② )) ✐♥ 3 4 ❞❡❢ mixin = ( ❵♥❡❛r❩❡r♦ _ & ❵s❡❧❢ s❡❧❢ -> ( s❡❧❢ ❵❧✶ ✭✮ ) <= 4) ✐♥ 5 6 ❞❡❢ mixedPoint = seal (point & mixin) ✐♥ 7 mixedPoint ❵♥❡❛r❩❡r♦ ✭✮ Mixins
Other Features 1 ❞❡❢ point = . . . ✐♥ 2 ❞❡❢ mixin = (( ❵♥❡❛r❩❡r♦ _ & ❵s❡❧❢ s❡❧❢ -> ( s❡❧❢ ❵❧✶ ✭✮ ) <= 4)) ✐♥ 3 4 ❞❡❢ mixedPoint = seal (point & mixin) ✐♥ 5 mixedPoint ❵♥❡❛r❩❡r♦ ✭✮ Mixins Higher-order object extension
Other Features 1 ❞❡❢ obj = seal ( ❵① 0 & ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 2 s❡❧❢ . ① = s❡❧❢ . ① + 1 ✐♥ s❡❧❢ . ① )) ✐♥ 3 4 ❞❡❢ obj2 = seal ( (obj &. ❵① ) & ❵② 0 & 5 ( ❵✐♥❝ _ & ❵s❡❧❢ s❡❧❢ -> 6 s❡❧❢ . ② = s❡❧❢ . ② + s❡❧❢ . ① ✐♥ s❡❧❢ . ② )) ✐♥ 7 8 . . . Mixins Higher-order object extension Data sharing
Other Features 1 ❞❡❢ obj = seal ( ❵① 0 & 2 ( ❵✐♥❝ n: ✐♥t & ❵s❡❧❢ s❡❧❢ -> 3 s❡❧❢ . ① = s❡❧❢ . ① + n ✐♥ s❡❧❢ . ① ) & 4 ( ❵✐♥❝ n: ✉♥✐t & ❵s❡❧❢ s❡❧❢ -> 5 s❡❧❢ ❵✐♥❝ 1) ✐♥ 6 7 obj ( ❵✐♥❝ ✭✮ ); obj ( ❵✐♥❝ 4) Mixins Higher-order object extension Data sharing Overloading
Other Features etc. Mixins Higher-order object extension Data sharing Overloading Classes, inheritance, etc.
Type Inference
Type Inference Subtype constraint system
Type Inference Subtype constraint system Assign each subexpression a type variable
Type Inference Subtype constraint system Assign each subexpression a type variable Derive initial constraint set over expression
Type Inference Subtype constraint system Assign each subexpression a type variable Derive initial constraint set over expression Perform knowledge closure on constraints
Type Inference 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
Type Inference 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
Constraint Types int ∪ unit
Constraint Types int ∪ unit � α \{ int < : α, unit < : α }
Recommend
More recommend