◭ ◭ ◭ ◮ ◮ ◮ ◭
- ×
Parametric Type Inferencing for Helium Bastiaan Heeren and Jurriaan - - PowerPoint PPT Presentation
Parametric Type Inferencing for Helium Bastiaan Heeren and Jurriaan Hage Institute of Information and Computing Science Utrecht University e-mail: { bastiaan,jur } @cs.uu.nl September 17, 2002 The Helium
◭ ◭ ◭ ◮ ◮ ◮ ◭
1 ◭ ◭ ◭ ◮ ◮ ◮ ◭
UHA UHA .hs
.core lvmToBytes coreToAsm asmToLvm
2 ◭ ◭ ◭ ◮ ◮ ◮ ◭
3 ◭ ◭ ◭ ◮ ◮ ◮ ◭
4 ◭ ◭ ◭ ◮ ◮ ◮ ◭
e BU e : τ for expression e consists of:
M, {x:β}, ∅ ⊢
e BU x : β
[Var]e
BU
M, A1, C1 ⊢
e BU e1 : τ1
M, A2, C2 ⊢
e BU e2 : τ2
M, A3, C3 ⊢
e BU e3 : τ3
M, A1 ∪ A2 ∪ A3, C1 ∪ C2 ∪ C3 ∪ {τ1 ≡ Bool, τ2 ≡ β, τ3 ≡ β} ⊢
e BU if e1 then e2 else e3 : β
[If]e
BU
Bi, Ci ⊢
p BU pi : τi for 1 ≤ i ≤ n
B =
i Bi
M ∪ ran(B), A, C ⊢
e BU e : τ
M, A\dom(B),
i Ci ∪ C ∪ (B ≡ A) ∪ {β ≡ τ1 → . . . → τn → τ} ⊢ e BU (λp1 . . . pn → e) : β
[Abs]e
BU
5 ◭ ◭ ◭ ◮ ◮ ◮ ◭
6 ◭ ◭ ◭ ◮ ◮ ◮ ◭
u m u u m u u m u u m u b b b b then lhs
If Expr Expr
else guard
Expr
c c c c a a a a
6 ◭ ◭ ◭ ◮ ◮ ◮ ◭
u m u u m u u m u u m u b b b b then lhs
If Expr Expr
else guard
Expr
loc b c c c c a a a a
6 ◭ ◭ ◭ ◮ ◮ ◮ ◭
u m u u m u u m u u m u b b b b then lhs
If Expr Expr
else guard
Expr
loc b c c c c a a a a
6 ◭ ◭ ◭ ◮ ◮ ◮ ◭
u m u u m u u m u u m u b b b b then lhs
If Expr Expr
else guard
Expr
loc b c c c c a a a a
6 ◭ ◭ ◭ ◮ ◮ ◮ ◭
u u m u u m u u m u u m guard b b b b then lhs
If Expr Expr
else
Expr
loc b c c c c a a a a
6 ◭ ◭ ◭ ◮ ◮ ◮ ◭
u u m u u m u u m u m guard u b b b b then lhs
If Expr Expr
else
Expr
loc b c c c c a a a a
7 ◭ ◭ ◭ ◮ ◮ ◮ ◭
Bi, Ci ⊢
p BU pi : τi for 1 ≤ i ≤ n
B =
i Bi
M ∪ ran(B), A, C ⊢
e BU e : τ
M, A\dom(B),
i Ci ∪ C ∪ (B ≡ A) ∪ {β ≡ τ1 → . . . → τn → τ} ⊢ e BU (λp1 . . . pn → e) : β
[Abs]e
BU
8 ◭ ◭ ◭ ◮ ◮ ◮ ◭
W spread + postorder M spread + preorder Bottom-Up no spread + postorder
v6 v2
v0 v1 v7 v7 = v0 -> v1 -> v6 v0 = v3 v1 = v4 v2 = v5 -> v6 v3 = v4 -> v5 v5 v4 v3 v0 = v2
9 ◭ ◭ ◭ ◮ ◮ ◮ ◭
10 ◭ ◭ ◭ ◮ ◮ ◮ ◭
11 ◭ ◭ ◭ ◮ ◮ ◮ ◭
12 ◭ ◭ ◭ ◮ ◮ ◮ ◭
13 ◭ ◭ ◭ ◮ ◮ ◮ ◭
#17 #14 #16 #18 #3 #2 #15 #7 #11 #12 #22 #21 #6 #5 #4 #8 #19 #9 #10 #13 #20 #1 (1) (2) (1) (2) (2) (1) (2) (1) (1) (1) (2) (2) (2) (1) (1) (2)
14 ◭ ◭ ◭ ◮ ◮ ◮ ◭
#18 #3 #2 #15 #7 #11 #12 #22 #21 #6 #5 #4 #8 #19 #9 #10
f 0 y = y f x y = if y then x else f (x − 1) y
14 ◭ ◭ ◭ ◮ ◮ ◮ ◭
#18 #3 #2 #15 #7 #11 #12 #22 #21 #6 #5 #4 #8 #19 #9 #10
f 0 y = y f x y = if y then x else f (x − 1) y
14 ◭ ◭ ◭ ◮ ◮ ◮ ◭
#18 #3 #2 #15 #7 #11 #12 #22 #21 #6 #5 #4 #8 #19 #9 #10
f 0 y = y f x y = if y then x else f (x − 1) y
ERROR "Test.hs":2 - Type error in conditional *** Expression : if y then x else f (x - 1) y *** Term : f (x - 1) y *** Type : Bool *** Does not match : Int
14 ◭ ◭ ◭ ◮ ◮ ◮ ◭
#18 #3 #2 #15 #7 #11 #12 #22 #21 #6 #5 #4 #8 #19 #9 #10
f 0 y = y f x y = if y then x else f (x − 1) y
Test.hs:2: Couldn’t match ‘Bool’ against ‘Int’ Expected type: Bool Inferred type: Int In the definition of ‘f’: if y then x else f (x - 1) y
14 ◭ ◭ ◭ ◮ ◮ ◮ ◭
#18 #3 #2 #15 #7 #11 #12 #22 #21 #6 #5 #4 #8 #19 #9 #10
f 0 y = y f x y = if y then x else f (x − 1) y
(2,12): Type error in conditional Expression : if y then x else f (x - 1) y Term : y Type : Int Does not match : Bool
14 ◭ ◭ ◭ ◮ ◮ ◮ ◭
#18 #3 #2 #15 #7 #11 #12 #22 #21 #6 #5 #4 #8 #19 #9 #10
f 0 y = y f x y = if y then x else f (x − 1) y
(1,9): Type error in rhs of function binding Expression : y Type : Bool Does not match : Int
14 ◭ ◭ ◭ ◮ ◮ ◮ ◭
#18 #3 #2 #15 #7 #11 #12 #22 #21 #6 #5 #4 #8 #19 #9 #10
f 0 y = y f x y = if y then x else f (x − 1) y
(2,19): Type error in conditional Expression : if y then x else f (x - 1) y Term : x Type : Int Does not match : Bool
15 ◭ ◭ ◭ ◮ ◮ ◮ ◭