Download presentation
Presentation is loading. Please wait.
Published byKarson Osen Modified over 9 years ago
1
Type Reconstruction (II) - Algorithm W - 20110205 CSE 김민철 (id: rucatia) 6/4 POSTECH 무은재기념관 307 호
2
Implicit let-polymorphism Type Annotation X Type Abstraction X Type Application X A :: = A A | α U :: = A | ∀ α.U e :: = x | λx.e | e e | let x = e in e Γ :: = · | Γ, x : U, α type
3
Rules for typing judgement Γ ▷ e:U Bottom up Algorithm W 를 간단하게 !
4
Type reconstruction Implicit let-polymorphism 에서 type reconstruction! A :: = A A | α U :: = A | ∀ α.U e :: x | λx.e | e e | let x = e in e Γ :: = · | Γ, x : U[ 모든 type 이 유효하다는 Assumption! (No Γ, α type)]
5
Revised version of Gen, Spec rule Top down Approach 의도하지 않은 중복 방지 ! Polytype -> Monotype
6
Algorithm W
7
λx. x+1 Function body 를 안 봐서 x 의 타입은 그냥 임의로 α Body 에서 x 가 int 임을 얻음 {int/α} ({int/α}·α A) 가 최종 type
8
Algorithm W 3. W(Γ, e1 e2) = let (S1, A1) = W(Γ, e1) in let (S2, A2) = W(S1·Γ, e2) in let S3 = Unify(S2·A1 = A2 α) infresh α (S3 o S2 o S1, S3·α) Application Rule 을 잘 생각해보면 ? Unify 는 안의 Equation 의 type 이 같도록 하는 Substitution 을 return 한다. Γ S1·ΓA1??? e1e2 S2·S1·ΓS2·A1A2 S3·S2·A1S3·A2
9
Unify Function type equations E ::= · | A = A Unify(E) = S [Substitution S 를 적용하면 type equation E 는 true S·E] Unify(·) = id Unify(E, α = A) =if α = A then Unify(E) else if α ∈ ftv(A) then fail else Unify({A/α}·E) o {A/α} Unify(E, A1 A2 = B1 B2) = Unify(E, A1=B1, A2=B2) Unify(α = α int) E 가 α 를 가지고 있을 때를 생각해보자. Unify(α β = β α, α = int)
10
Algorithm W Γ Γ S1·ΓA1??? e1 e2 S2·S1·ΓA2 Gen(A1) x x USE αβαβ ∀α.αβ∀α.αβ ∀β.∀α.αβ∀β.∀α.αβ Gen Rule Gen Function
11
Completeness of Algorithm W
12
Thank you! Thanks for 류각사
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.