1 / 13

Existential Types

Existential Types. Polymorphic Type Inference and Abstract Data Types by Martin Odersky. Table Of Content. Existential type Syntax of ExML Formal syntax of ExML Type inference rules Type inference algorithm Semantic function. Existential Type. [Mit88] and [Cardelli85]

dezso
Download Presentation

Existential Types

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Existential Types Polymorphic Type Inference and Abstract Data Typesby Martin Odersky

  2. Table Of Content • Existential type • Syntax of ExML • Formal syntax of ExML • Type inference rules • Type inference algorithm • Semantic function

  3. Existential Type • [Mit88] and [Cardelli85] • abstype complex with creat: real →real → complex, plus: complex → complex, re: complex → real, im: complex → realispack real ∧ realλx: real. λy: real. <x, y>λz: real ∧ real. λw: real ∧ real. <fst(z) + fst(w), snd(z) + snd(w)>λz: real ∧ real. fst(z)λz: real ∧ real. snd(z)to ∃t. [(real → real → t) ∧ (t → t) ∧(t → real) ∧ (t → real)]

  4. Syntax of ExML • type [args] T = K1ofτ1 | … | Kkofτk • type KEY = Key of‘a * (‘a -> int) • Key(3, fun x -> 5) • Key([1, 2, 3], list_length) • Key(3, list_length) (* error *) • let (Key(v,f)) = x in f v • let (Key(v,f)) = x in v (* error *)

  5. Syntax of ExML (cont.) • type Key = {x : ‘a; f : ‘a -> int} • let z = {x = 3, f = fun x -> x + 2} in z.f z.x • let z = {x = 3, f = fun x -> x + 2} in z.f (* error *) • let z = {x = 3, f = fun x -> x + 2} inlet y = z in z.f y.x (* error *)

  6. Syntax of ExML (cont.) • type‘a STACK = {Self : ‘b; Push : ‘a -> ‘b -> ‘b; Pop : ‘b -> ‘b; Top : ‘b -> ‘a; Null : ‘b -> bool} • let push x s = s with {Self = s.Push x s.Self} • let top s = s.Top s.Self

  7. Formal Syntax of ExML

  8. Original Type Inference Rule

  9. Type Inference Rule Extension

  10. Original Type Inference Algorithm

  11. Type Inference Algorithm Extension

  12. Semantic Function for Expression

  13. Semantic Function for Types

More Related