Upload
dezso
View
31
Download
0
Embed Size (px)
DESCRIPTION
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] - PowerPoint PPT Presentation
Citation preview
Existential TypesExistential Types
Polymorphic Type Inference and Polymorphic Type Inference and Abstract Data TypesAbstract Data Typesby Martin Oderskyby Martin Odersky
Table Of ContentTable Of Content
Existential typeExistential type Syntax of ExMLSyntax of ExML Formal syntax of ExMLFormal syntax of ExML Type inference rulesType inference rules Type inference algorithmType inference algorithm Semantic functionSemantic function
Existential TypeExistential Type [Mit88] and [Cardelli85][Mit88] and [Cardelli85] abstypeabstype complex complex withwith
creat: real creat: real →real → complex,→real → complex, plus: complex → complex, plus: complex → complex, re: complex → real, re: complex → real, im: complex → real im: complex → realisispackpack real real ∧ ∧ realreal λλx: real. x: real. λλy: real. <x, y>y: real. <x, y> λλz: real z: real ∧∧ real. real. λλw: real w: real ∧∧ real. real. <fst(z) + fst(w), snd(z) + snd(w)> <fst(z) + fst(w), snd(z) + snd(w)> λλz: real z: real ∧∧ real. fst(z) real. fst(z) λλz: real z: real ∧∧ real. snd(z) real. snd(z)to to ∃t. [(real ∃t. [(real →→ real real →→ t) t) ∧ ∧ (t (t → t) → t) ∧∧ (t → real) (t → real) ∧ ∧ (t → real)(t → real)] ]
Syntax of ExMLSyntax of ExML
typetype [args] T = K [args] T = K11 ofof ττ 11 | … | K | … | Kkk ofof ττ kk typetype KEY = Key KEY = Key ofof ‘a * (‘a -> int) ‘a * (‘a -> int) Key(3, fun x -> 5)Key(3, fun x -> 5) Key([1, 2, 3], list_length)Key([1, 2, 3], list_length) Key(3, list_length) Key(3, list_length) (* error *)(* error *) letlet (Key(v,f)) = x (Key(v,f)) = x inin f v f v letlet (Key(v,f)) = x (Key(v,f)) = x inin v v (* error *)(* error *)
Syntax of ExML (cont.)Syntax of ExML (cont.)
typetype Key = {x : ‘a; f : ‘a -> int} Key = {x : ‘a; f : ‘a -> int} letlet z = {x = 3, f = fun x -> x + 2} z = {x = 3, f = fun x -> x + 2} inin
z.f z.x z.f z.x letlet z = {x = 3, f = fun x -> x + 2} z = {x = 3, f = fun x -> x + 2} inin
z.f z.f (* error *)(* error *) letlet z = {x = 3, f = fun x -> x + 2} z = {x = 3, f = fun x -> x + 2} inin
letlet y = z y = z inin z.f y.x z.f y.x (* error *)(* error *)
Syntax of ExML (cont.)Syntax of ExML (cont.)
typetype ‘a STACK = ‘a STACK = {Self : ‘b; {Self : ‘b; Push : ‘a -> ‘b -> ‘b; Push : ‘a -> ‘b -> ‘b; Pop : ‘b -> ‘b; Pop : ‘b -> ‘b; Top : ‘b -> ‘a; Top : ‘b -> ‘a; Null : ‘b -> bool} Null : ‘b -> bool}
letlet push x s = s with {Self = s.Push x s.Self} push x s = s with {Self = s.Push x s.Self} letlet top s = s.Top s.Self top s = s.Top s.Self
Formal Syntax of ExMLFormal Syntax of ExML
Original Type Inference RuleOriginal Type Inference Rule
Type Inference Rule ExtensionType Inference Rule Extension
Original Type Inference AlgorithmOriginal Type Inference Algorithm
Type Inference Algorithm ExtensionType Inference Algorithm Extension
Semantic Function for ExpressionSemantic Function for Expression
Semantic Function for TypesSemantic Function for Types