110 likes | 231 Views
Type Reconstruction (1). 20110248 CSE 김형준 5 월 30 일 무은재 기념관 308 호. Type Reconstruction for implicit polymorphism. Remind Γ▷ e : U Given untyped expression e can have type U ㆍ ▷ λx.x : int → int ㆍ ▷ λx.x : bool → bool ㆍ ▷ λx.x : ∀ α . α → α All these typings make sense.
E N D
Type Reconstruction (1) 20110248 CSE 김형준 5월 30일 무은재 기념관 308호
Type Reconstruction for implicit polymorphism Remind Γ▷e : U Given untyped expression e can have type U ㆍ ▷ λx.x : int → int ㆍ ▷ λx.x : bool → bool ㆍ ▷ λx.x : ∀α. α→α All these typings make sense.
Untyped expressions set Types set e
Untyped expressions set Types set λx.x int → int bool → bool …
System Modification Bottom up Top down
Gen rule • Why we need to check whether a is fresh or not? If we reuse type variable which is not fresh under gamma, there may occur unintended link between unrelated variable actually.
Spec rule • Why we need Spec rule? • To instantiate polytype variable x to monotype so that we can use x polymorphically.
Algorithm W • W(Γ,e) = (S,A) • type Substitution S ::= id | {A/α} | S о S • mapping from type variables to monotypes • why not polytypes? • In my opinion, we may introduce type variable when typing lambda abstraction, and the lambda binder must be monotype in let polymorphism which is base of implicit polymorphism.
Question • When we talk about Most General type, by its definition, λx.x can have another most general type which is ∀β.∀α. α→α. This type also can be instantiated to all types that ∀α. α→α can be. So we need more constraint to define most general type strictly. • In my opinion, this constraint may work. This kind of unrealistic situation happens because we can create a type variables which is not used actually, so every introduced type variables must be used at least once in body. Otherwise it is not most general type because it has meaningless part(not optimization).