Presentation is loading. Please wait.

Presentation is loading. Please wait.

Practice session #4: Static Type Correctness Algorithms:

Similar presentations


Presentation on theme: "Practice session #4: Static Type Correctness Algorithms:"— Presentation transcript:

1 Practice session #4: Static Type Correctness Algorithms:
Axiomatic type inference Type inference using type constraints שפה שהינה typed, היא שפה התומכת בסמנטיקה שלה בטיפוסים. היא מאפשרת לייחס טיפוסים שונים לערכים ולמבנים של ערכים. כל השפות הפרקטיות הן כאלה. שפות שהן typed כוללות גם אוסף של חוקים לפיהם ניתן לשלב טיפוסים באופן נכון. המטרה של בדיקת / הסקת טיפוסים היא להבטיח שהשימוש בטיפוסים בשפה הוא נכון ולמנוע את החישוב במקרה שלא. Scheme היא fully typed, בעלת un-typed syntax ותהליך הסקת הטיפוסים בה נעשה תוך כדי תהליך החישוב. כלומר, היא dynamically typed.

2 Static Type Correctness Algorithms
General Definitions: Type-substitution: A mapping, s, from a finite set of type variables to a finite set of type expressions, such that for every type variable T, s(T) does not include T. Type-binding: A pair ⟨T,s(T)⟩ such that T = s(T). Type-Substitutions are written using set notation, e.g. : {T1 = Number, T2 = [Number -> T3]} {T1 = Number, T2 = [[Number -> T3]->T2} Q: Is the last set of type-bindings a legal type-substitution?

3 Static Type Correctness Algorithms
General Definitions: Application of type-substitution: An application of a type-substitution s on a type-expression TE, denoted as TE ○ s, is a consistent replacement of type variables T in TE by their mapped type-expressions s(T). For example: [[T1->T2]->T2] ○ {T1=Boolean, T2=[T3->T3]} = [[Boolean->[T3->T3]] -> [T3->T3]]

4 Static Type Correctness Algorithms
General Definitions: Composition of type substitution: The composition of type-substitutions s and s’, denoted s○s’, is defined by: s’ is applied to type-expressions of s: for every type-variable T for which s(T) is defined, occurrences of type-variables T’ in s(T) are replaced by s’(T’). A variable T for which s(T) is defined, is removed from the domain of s’. The modified s’ is add to s. Identity bindings, i.e., s(T)=T, are removed. E.g.,: s = {T1=Number, T2=[[Number -> T3] -> T3]} , s‘ = {T3=Boolean, T1=[T2->T2]} s = {T1=Number, T2=[[Number -> Boolean] -> Boolean]} , s‘ = {T3=Boolean, T1=[T2->T2]} s = {T1=Number, T2=[[Number -> Boolean] -> Boolean]} , s‘ = {T3=Boolean} s = {T1=Number, T2=[[Number -> Boolean] -> Boolean], T3=Boolean} , s‘ = {T3=Boolean} s○s’,= {T1=Number, T2=[[Number -> Boolean] -> Boolean] , T3=Boolean}

5 Static Type Correctness Algorithms: Axiomatic type inference
Terminology: Type environment: A substitution of language-variables by type-expressions, denoted as a set of variable-type assumptions. Extending a type environment is performed by the substitution composition. For example, {x:Number, y:[Number->T]}. Typing statement: A true/false formula that states a judgment about the type of a language expression, given a type environment to variables. It has the following notation: Tenv |- e:T which states: “Under the type environment Tenv, the expression e has type T”. For example: {x:Number} |- (+ 3 x):Number states that under the assumption that the type of x is Number, the type of (+ 3 x) is Number.

6 Static Type Correctness Algorithms: Axiomatic type inference
Terminology: Instantiation of typing statement: An instance of a typing statements TS is a typing statement TS’ that results from the application of a type-substitution s to all type expressions in TS: TS’ = TS ○ s Q: What can be implied from the following statement? {x:[T1->T2]}|-(x e):T2 An expression e is well typed if Type-derivation(e) does not fail, i.e.: Type-derivation(e)=〈TS, derivation〉, where derivation is the set of typing statements obtained during the type inference for e. e has type t if it is well typed and Type-derivation(e)= 〈{ } |- e:t,derivation〉.

7 Static Type Correctness Algorithms: Axiomatic type inference
Question 1: Derive the type of the following expression: (lambda(x) (+ 7 x)) Step 1 – Renaming: (lambda(x1) (+ 7 x1)) Step 2 – Initialize: dervied-ts-pool = { } Step 3 – Typing leaf expressions: (lambda(x1) (+ 7 x1)) (+ 7 x1) + 7 x1 במהלך בדיקת הטיפוסים, נשמור אוסף של מסקנות לגבי טיפוסים של תת ביטויים אשר לפיהם נסיק טיפוסים של ביטויים גדולים יותר. אוסף זה נקרא derived-ts-pool. כל מסקנה שנכנסת אל ה – Pool נובעת משלושה שלבים: למצוא את האקסיומה / כלל הרלוונטיים למצוא substitution להפעיל את ה – substitution על האקסיומה / הכלל. Start with typing the leaves: + ; 7; x1 Q: What typing rules / axioms should be used for typing the leaves?

8 Static Type Correctness Algorithms: Axiomatic type inference
Question 1: Derive the type of the following expression: (lambda(x) (+ 7 x)) Typing the expression 7 : Typing axiom Number: For every type environment _Tenv and number _n: _Tenv |- _n: Number Finding the replacement: _Tenv = {}, s = {_n = 7} Q: Why is the empty environment chosen as replacement for _Tenv ? (_Tenv |- _n: Number) ○ s : (lambda(x1) (+ 7 x1)) (+ 7 x1) + 7 x1 הפעלה של אקסיומה / כלל כוללת החלפה של meta-variables בערכים ובביטויים מהשפה. בחרנו בסביבה הריקה כדי להחליף את _Tenv כיוון שההגדרה עבור well-typing דורשת לסיים את תהליך ההוכחה עם סביבה ריקה. ככל אצבע: תמיד נבחר את הסביבה המינימאלית כהחלפה. derived-ts-pool= {(1) { } |- 7 : Number}

9 Static Type Correctness Algorithms: Axiomatic type inference
Question 1: Derive the type of the following expression: (lambda(x) (+ 7 x)) Typing the expression + : Typing axiom Primitive +: For every type environment _Tenv: _Tenv |- +: [Number*Number -> Number] Finding the replacement: _Tenv = {} , s={} (_Tenv |- +: [Number*Number -> Number]) ○ s : (lambda(x1) (+ 7 x1)) (+ 7 x1) + 7 x1 derived-ts-pool= {(1) { } |- 7 : Number (2) { } |- + : [Number*Number -> Number]}

10 Static Type Correctness Algorithms: Axiomatic type inference
Question 1: Derive the type of the following expression: (lambda(x) (+ 7 x)) Typing the expression x1 : Typing axiom Variable: For every type environment _Tenv and variable _v : _Tenv |- _v: _Tenv(_v) Finding the replacement: _Tenv = {x1:T}, s = {_v = x1} (_Tenv |- _v: _Tenv(_v)) ○ s : (lambda(x1) (+ 7 x1)) (+ 7 x1) + 7 x1 derived-ts-pool= {(1) { } |- 7 : Number (2) { } |- + : [Number*Number -> Number] (3) {x1:T} |- X1 : T}

11 Static Type Correctness Algorithms: Axiomatic type inference
Question 1: Derive the type of the following expression: (lambda(x) (+ 7 x)) Step 4 – Typing non-leaf expressions: Typing the expression (+ 7 x1) : Typing rule Application: For every: type environment Tenv, expressions _f, _e1, _e2, and type expressions _S1,_S2, _S: If _Tenv |- _f:[_S1*_S2 -> _S], _Tenv |- _e1:_S1, _Tenv |- _e2:_S Then _Tenv |- (_f _e1 _e2):_S x1 derived-ts-pool= {(1) { } |- 7 : Number (2) { } |- + : [Number*Number -> Number] (3) {x1:T} |- X1 : T}

12 Static Type Correctness Algorithms: Axiomatic type inference
Question 1: Derive the type of the following expression: (lambda(x) (+ 7 x)) Step 4 – Typing non-leaf expressions: pool= {1.{}|-7:N 2.{}|-+:[N*N->N] 3.{x1:T}|-x1:T} Typing the expression (+ 7 x1) : Instance of Typing rule Application: For every: type environment Tenv, expressions +, 7, x1, and type expressions _S1,_S2, _S: If _Tenv |- +:[_S1*_S2 -> _S], _Tenv |- 7:_S1, _Tenv |- x1:_S Then _Tenv |- (+ 7 x1):_S With _Tenv = { }, s = {_S1 = N, _S2 = N, _S = N}, we get the typing statements: (1) and (2), but not (3). By rule of Monotonicity, we can extend a type-environment in a typing statement without losing the correctness of the original typing statement.

13 Static Type Correctness Algorithms: Axiomatic type inference
Question 1: Derive the type of the following expression: (lambda(x) (+ 7 x)) Step 4 – Typing non-leaf expressions: pool= {1.{}|-7:N 2.{}|-+:[N*N->N] 3.{x1:T}|-x1:T 4.{x1:N}|-(+ x 7):N Typing the expression (+ 7 x1) : Instance of Typing rule Application: For every: type environment Tenv, expressions +, 7, x1, and type expressions _S1,_S2, _S: If _Tenv |- +:[_S1*_S2 -> _S], _Tenv |- 7:_S1, _Tenv |- x1:_S Then _Tenv |- (+ 7 x1):_S With _Tenv = {x1:T}, s = {_S1 = N, _S2 = N, _S = N, T = N}, and using monotonicity, we get (1) (2) and (3). ({x1:T} |- (+ 7 x1):_S) ○ s is added to the pool.

14 Static Type Correctness Algorithms: Axiomatic type inference
Question 1: Derive the type of the following expression: (lambda(x) (+ 7 x)) Typing the expression (lambda (x1) (+ 7 x1)) : Typing rule Procedure: For every: type environment Tenv, variables _x1, ..., _xn, n >= expressions _b1, ..., _bm, m >= 1, and type expressions _S1, ...,_Sn, _U1, ...,_Um: If _Tenv ∘{_x1:_S1, ...,_xn:_Sn }|- _bi:_Ui for all i=1..m Then _Tenv |- (lambda (_x1 ... _x_n ) _b1 ... _bm) : [_S1*...*_Sn -> _Um] With _Tenv = { }, and s = {_S1 = N, _U1=N}, we get typing-statement (4). ({} |- (lambda (x1) (+ 7 x1)) :[_S1->_U1]) ○ s is added to the pool. pool= {1.{}|-7:N 2.{}|-+:[N*N->N] 3.{x1:T}|-x1:T 4.{x1:N}|-(+ x 7):N 5.{}|-(lambda(x1) (+ x1 7)):[N->N] x1 (+ 7 x1) Output: { {}|-(lambda(x1) (+ x1 7)):[N->N], pool } (lambda (x1) (+ 7 x1)) is well-typed and its type is [N->N]

15 Static Type Correctness Algorithms: Axiomatic type inference
Question 2: Derive the type of (lambda(x) (+ y (- x 1))) Step 1 – Renaming: (lambda(x1) (+ y (- x1 1))) Step 2 – Initialize: dervied-ts-pool = { } Step 3 – Typing leaf expressions: pool= {1.{ }|- +:[N*N->N] 2.{y:T1}|- y:T1 3.{ }|- -:[N*N->N] 4.{x1:T2}|-x1:T2 5.{ }|-1:N (lambda (x1)(+ y (- x1 1))) (+ y (- x1 1)) + y (- x1 1) - x1 1

16 Static Type Correctness Algorithms: Axiomatic type inference
Question 2: Derive the type of (lambda(x) (+ y (- x 1))) Step 4 – Typing non-leaf expressions: pool= {1.{ }|- +:[N*N->N] 2.{y:T1}|- y:T1 3.{ }|- -:[N*N->N] 4.{x1:T2}|-x1:T2 5.{ }|-1:N Typing the expression (- x1 1) : Typing rule Application: For every: type environment Tenv, expressions _f, _e1, _e2, and type expressions _S1,_S2, _S: If _Tenv |- _f:[_S1*_S2 -> _S], _Tenv |- _e1:_S1, _Tenv |- _e2:_S Then _Tenv |- (_f _e1 _e2):_S With _Tenv = { }, and s = {_S1 = N, _S2=N, _S=N}, we get (3), (5), but not (4). Q: What would be the appropriate _Tenv to choose? - x1 1

17 Static Type Correctness Algorithms: Axiomatic type inference
Question 2: Derive the type of (lambda(x) (+ y (- x 1))) Step 4 – Typing non-leaf expressions: pool= {1.{ }|- +:[N*N->N] 2.{y:T1}|- y:T1 3.{ }|- -:[N*N->N] 4.{x1:T2}|-x1:T2 5.{ }|-1:N 6. { x1:N} |- (- x1 1) :N Typing the expression (- x1 1) : Typing rule Application: For every: type environment Tenv, expressions _f, _e1, _e2, and type expressions _S1,_S2, _S: If _Tenv |- _f:[_S1*_S2 -> _S], _Tenv |- _e1:_S1, _Tenv |- _e2:_S Then _Tenv |- (_f _e1 _e2):_S With _Tenv = { x1:N}, and s = {_S1 = N, _S2=N, _S=N}, using monotonicity, we get (3), (5), (4). ({ x1:N} |- (- x1 1) :_S) ○ s is added to the pool. - x1 1

18 Static Type Correctness Algorithms: Axiomatic type inference
Question 2: Derive the type of (lambda(x) (+ y (- x 1))) Typing the expression (+ y (- x1 1)) : Typing rule Application: For every: type environment Tenv, expressions _f, _e1, _e2, and type expressions _S1,_S2, _S: If _Tenv |- _f:[_S1*_S2 -> _S], _Tenv |- _e1:_S1, _Tenv |- _e2:_S Then _Tenv |- (_f _e1 _e2):_S With _Tenv = {}, and s = {_S1 = N, _S2=N, _S=N}, what do we get? (1), but neither (2) nor (6). pool= {1.{ }|- +:[N*N->N] 2.{y:T1}|- y:T1 3.{ }|- -:[N*N->N] 4.{x1:T2}|-x1:T2 5.{ }|-1:N 6.{x1:N}|- (- x1 1):N + y (- x1 1)

19 Static Type Correctness Algorithms: Axiomatic type inference
Question 2: Derive the type of (lambda(x) (+ y (- x 1))) Typing the expression (+ y (- x1 1)) : Typing rule Application: For every: type environment Tenv, expressions _f, _e1, _e2, and type expressions _S1,_S2, _S: If _Tenv |- _f:[_S1*_S2 -> _S], _Tenv |- _e1:_S1, _Tenv |- _e2:_S Then _Tenv |- (_f _e1 _e2):_S With _Tenv = {y:N,x1:N}, and s = {_S1 = N, _S2=N, _S=N, _T=N}, we get (1), (2), (6). ({ y:N,x1:N} |- (+ y (- x1 1)) :_S) ○ s is added to the pool. pool= {1.{ }|- +:[N*N->N] 2.{y:T1}|- y:T1 3.{ }|- -:[N*N->N] 4.{x1:T2}|-x1:T2 5.{ }|-1:N 6.{ x1:N}|- (- x1 1):N 7.{y:N,x1:N}|- (+ y (- x1 1)):N + y (- x1 1)

20 Static Type Correctness Algorithms: Axiomatic type inference
Question 2: Derive the type of (lambda(x) (+ y (- x 1))) Typing the expression (lambda (x1) (+ y (- x1 1))) : Typing rule Procedure: For every: type environment Tenv, variables _x1, ..., _xn, n >= expressions _b1, ..., _bm, m >= 1, and type expressions _S1, ...,_Sn, _U1, ...,_Um: If _Tenv ∘{_x1:_S1, ...,_xn:_Sn }|- _bi:_Ui for all i=1..m Then _Tenv |- (lambda (_x1 ... _x_n ) _b1 ... _bm) : [_S1*...*_Sn -> _Um] With _Tenv = {y:N}, and s = {_S1 = N, _U1=N}, we get typing-statement (7). ({y:N} |- (lambda (x1) (+ y (- x1 1))) :[_S1->_U1]) ○ s is added to the pool. pool= {1.{ }|- +:[N*N->N] 2.{y:T1}|- y:T1 3.{ }|- -:[N*N->N] 4.{x1:T2}|-x1:T2 5.{ }|-1:N 6.{ x1:N}|- (- x1 1):N 7.{y:N,x1:N}|- (+ y (- x1 1)):N 8.{y:N}|- (lambda(x1) (+ y (- x1 1))):[N->N] x1 (+ y (- x1 1)) Output: {(8),pool}

21 Type checking and inference Using type constraints
Applications of typing axioms / rules are replaced with type equations. A 3-stages algorithm. Given an expression, e: Rename bound variables in e. Assign type variables to all sub-expressions of e. Construct type equations. Solve the equations. Question 1: Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-I: Rename bound variables None needed: No other references of variables f and x. STAGE-II: Assign type variables to all sub-exps Expression Var ((lambda(f x) (f x)) sqrt 4) T0 (lambda(f x) (f x)) T1 (f x) T2 f Tf x Tx sqrt Tsqrt 4 Tnum4

22 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-III: Construct type equations. Atomic exps / primitive-procs Construct equations using their types. Lambda expressions For (lambda (v vn) e em), construct: Application expressions For (f e en), construct: Expression Equation ((lambda (f x) (f x)) sqrt 4) T1:=[Tsqrt*Tnum4→T0] (lambda (f x) (f x)) T1:=[Tf*Tx→T2] Sqrt Tsqrt := [Number → Number] 4 Tnum4:=Number (f x) Tf:=[Tx→T2] Expression Var ((lambda(f x) (f x)) sqrt 4) T0 (lambda(f x) (f x)) T1 (f x) T2 f Tf x Tx sqrt Tsqrt 4 Tnum4

23 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 1. T1:=[Tsqrt*Tnum4→T0] 2. T1:=[Tf*Tx→T2] 3. Tf:=[Tx→T2] 4. Tsqrt := [N → N] 5. Tnum4:=N Equation 1: Apply step 1: Initially, the substitution is empty. Eq1 is moved to the substitution.

24 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 2. T1:=[Tf*Tx→T2] T1:=[Tsqrt*Tnum4→T0] 3. Tf:=[Tx→T2] 4. Tsqrt := [N → N] 5. Tnum4:=N Equation 1: Apply step 1: Initially, the substitution is empty. Eq1 is moved to the substitution.

25 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 2. T1:=[Tf*Tx→T2] T1:=[Tsqrt*Tnum4→T0] 3. Tf:=[Tx→T2] 4. Tsqrt := [N → N] 5. Tnum4:=N Equation 2: step 1: T1 is replaced by current substitution: [Tf* Tx -> T2] = [Tsqrt* Tnum4-> T0] Both side are composite, apply step 5: Equations are split and Eq2 is removed.

26 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 2. T1:=[Tf*Tx→T2] T1:=[Tsqrt*Tnum4→T0] 3. Tf:=[Tx→T2] 4. Tsqrt := [N → N] 5. Tnum4:=N 6. Tf:=Tsqrt 7. Tx:=Tnum4 8. T2:=T0 Equation 2: step 1: T1 is replaced by current substitution: [Tf* Tx -> T2] = [Tsqrt* Tnum4-> T0] Both side are composite, apply step 5: Equations are split and Eq2 is removed.

27 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 3. Tf:=[Tx→T2] T1:=[Tsqrt*Tnum4→T0] 4. Tsqrt := [N → N] 5. Tnum4:=N 6. Tf:=Tsqrt 7. Tx:=Tnum4 8. T2:=T0 Equation 3: step 1: No change. Eq3 is added to the substitution.

28 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 4. Tsqrt := [N → N] T1:=[Tsqrt*Tnum4→T0] 5. Tnum4:=N 3. Tf:=[Tx→T2] 6. Tf:=Tsqrt 7. Tx:=Tnum4 8. T2:=T0 Equation 3: step 1: No change. Eq3 is added to the substitution.

29 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 4. Tsqrt := [N → N] T1:=[Tsqrt*Tnum4→T0] 5. Tnum4:=N Tf:=[Tx→T2] 6. Tf:=Tsqrt 7. Tx:=Tnum4 8. T2:=T0 Equation 4: step 1: No change. Eq4 is added to the substitution: Any occurrence of Tsqrt is substituted by [N→N]

30 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 5. Tnum4:=N T1:=[[N → N]*Tnum4→T0] 6. Tf:=Tsqrt Tf:=[Tx→T2] 7. Tx:=Tnum4 Tsqrt := [N → N] 8. T2:=T0 Equation 4: step 1: No change. Eq4 is added to the substitution: Any occurrence of Tsqrt is substituted by [N→N]

31 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 5. Tnum4:=N T1:=[[N → N]*Tnum4→T0] 6. Tf:=Tsqrt Tf:=[Tx→T2] 7. Tx:=Tnum4 Tsqrt := [N → N] 8. T2:=T0 Equation 5: step 1: No change. Eq5 is added to the substitution: Any occurrence of Tnum4 is substituted by N

32 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 6. Tf:=Tsqrt T1:=[[N → N]*N→T0] 7. Tx:=Tnum4 Tf:=[Tx→T2] 8. T2:=T0 Tsqrt := [N → N] Tnum4:=N Equation 5: step 1: No change. Eq5 is added to the substitution: Any occurrence of Tnum4 is substituted by N

33 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 6. Tf:=Tsqrt T1:=[[N → N]*N→T0] 7. Tx:=Tnum4 Tf:=[Tx→T2] 8. T2:=T0 Tsqrt := [N → N] Tnum4:=N Equation 6: step 1: Tf and Tsqrt are substituted: [Tx→T2]=[N → N] Both side are composite, apply step 5: Equations are split and Eq6 is removed.

34 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 6. Tf:=Tsqrt T1:=[[N → N]*N→T0] 7. Tx:=Tnum4 Tf:=[Tx→T2] 8. T2:=T0 Tsqrt := [N → N] 9. Tx:=N Tnum4:=N 10. T2:=N Equation 6: step 1: Tf and Tsqrt are substituted: [Tx→T2]=[N → N] Both side are composite, apply step 5: Equations are split and Eq6 is removed.

35 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 7. Tx:=Tnum4 T1:=[[N → N]*N→T0] 8. T2:=T0 Tf:=[Tx→T2] 9. Tx:=N Tsqrt := [N → N] 10. T2:=N Tnum4:=N Equation 7: step 1: Tnum4 is substituted: Tx=N Eq7 is added to the substitution: Any occurrence of Tx is substituted for N

36 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 7. Tx:=N T1:=[[N → N]*N→T0] 8. T2:=T0 Tf:=[Tx→T2] 9. Tx:=N Tsqrt := [N → N] 10. T2:=N Tnum4:=N Equation 7: step 1: Tnum4 is substituted: Tx=N Eq7 is added to the substitution: Any occurrence of Tx is substituted for N

37 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 8. T2:=T0 T1:=[[N → N]*N→T0] 9. Tx:=N Tf:=[N→T2] 10. T2:=N Tsqrt := [N → N] Tnum4:=N Tx:=N Equation 7: step 1: Tnum4 is substituted: Tx=N Eq7 is added to the substitution: Any occurrence of Tx is substituted for N

38 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 8. T2:=T0 T1:=[[N → N]*N→T0] 9. Tx:=N Tf:=[N→T2] 10. T2:=N Tsqrt := [N → N] Tnum4:=N Tx:=N Equation 8: step 1: no change. Eq8 is added to the substitution: Any occurrence of T2 is substituted for T0

39 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 9. Tx:=N T1:=[[N → N]*N→T0] 10. T2:=N Tf:=[N→T0] Tsqrt := [N → N] Tnum4:=N Tx:=N T2:=T0 Equation 8: step 1: no change. Eq8 is added to the substitution: Any occurrence of T2 is substituted for T0

40 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 9. Tx:=N T1:=[[N → N]*N→T0] 10. T2:=N Tf:=[N→T0] Tsqrt := [N → N] Tnum4:=N Tx:=N T2:=T0 Equation 9: step 1: Tx is substituted: N=N Both sides are atomic and equal. Eq9 is removed.

41 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 9. N:=N T1:=[[N → N]*N→T0] 10. T2:=N Tf:=[N→T0] Tsqrt := [N → N] Tnum4:=N Tx:=N T2:=T0 Equation 9: step 1: Tx is substituted: N=N Both sides are atomic and equal. Eq9 is removed.

42 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 9. N:=N T1:=[[N → N]*N→T0] 10. T2:=N Tf:=[N→T0] Tsqrt := [N → N] Tnum4:=N Tx:=N T2:=T0 Equation 9: step 1: Tx is substituted: N=N Both sides are atomic and equal. Eq9 is removed.

43 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 10. T2:=N T1:=[[N → N]*N→T0] Tf:=[N→T0] Tsqrt := [N → N] Tnum4:=N Tx:=N T2:=T0 Equation 10: step 1: T2 is substituted: T0=N Eq10 is added to the substitution: Any occurrence of T0 is substituted for N

44 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 10. T0:=N T1:=[[N → N]*N→T0] Tf:=[N→T0] Tsqrt := [N → N] Tnum4:=N Tx:=N T2:=T0 Equation 10: step 1: T2 is substituted: T0=N Eq10 is added to the substitution: Any occurrence of T0 is substituted for N

45 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution T1:=[[N → N]*N→N] Tf:=[N→N] Tsqrt := [N → N] Tnum4:=N Tx:=N T2:=N T0:=N Equation 10: step 1: T2 is substituted: T0=N Eq10 is added to the substitution: Any occurrence of T0 is substituted for N

46 Type checking and inference
Using the type constraints approach Question 1 (cont’d): Typing the application ((lambda (f x) (f x)) sqrt 4) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution T1:=[[N → N]*N→N] Tf:=[N→N] Tsqrt := [N → N] Tnum4:=N Tx:=N T2:=N T0:=N Equation 10: step 1: T2 is substituted: T0=N Eq10 is added to the substitution: Any occurrence of T0 is substituted for N The type inference succeeds! The type of T0 is Number

47 Type checking and inference
Using the type constraints approach Question 2: Typing the application ((lambda (f x) (f x)) 4 sqrt) STAGE-I: Rename bound variables Unnecessary: No other references of variables f and x. STAGE-II: Assign type variables to all sub-exps Expression Var ((lambda(f x) (f x)) sqrt 4) T0 (lambda(f x) (f x)) T1 (f x) T2 f Tf x Tx 4 Tnum4 sqrt Tsqrt

48 Type checking and inference
Using the type constraints approach Question 2 (cont’d): Typing the application ((lambda (f x) (f x)) 4 sqrt) STAGE-III: Construct type equations. Atomic exps / primitive-procs Construct equations using their types. Lambda expressions For (lambda (v vn) e em), construct: Application expressions For (f e en), construct: Expression Equation ((lambda (f x) (f x)) 4 sqrt) T1:=[Tnum4*Tsqrt→T0] (lambda (f x) (f x)) T1:=[Tf*Tx→T2] 4 Tnum4:=N sqrt Tsqrt := [N → N] (f x) Tf:=[Tx→T2] Expression Var ((lambda(f x) (f x)) sqrt 4) T0 (lambda(f x) (f x)) T1 (f x) T2 f Tf x Tx 4 Tnum4 sqrt Tsqrt

49 Type checking and inference
Using the type constraints approach Question 2 (cont’d): Typing the application ((lambda (f x) (f x)) 4 sqrt) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 1. T1:=[Tnum4*Tsqrt→T0] 2. T1:=[Tf*Tx→T2] 3. Tf:=[Tx→T2] 4. Tnum4:=N 5. Tsqrt := [N → N] Equation 1: Apply step 1: Initially, the substitution is empty. Eq1 is moved to the substitution.

50 Type checking and inference
Using the type constraints approach Question 2 (cont’d): Typing the application ((lambda (f x) (f x)) 4 sqrt) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 2. T1:=[Tf*Tx→T2] T1:=[Tnum4*Tsqrt→T0] 3. Tf:=[Tx→T2] 4. Tnum4:=N 5. Tsqrt := [N → N] Equation 1: Apply step 1: Initially, the substitution is empty. Eq1 is moved to the substitution.

51 Type checking and inference
Using the type constraints approach Question 2 (cont’d): Typing the application ((lambda (f x) (f x)) 4 sqrt) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 2. T1:=[Tf*Tx→T2] T1:=[Tnum4*Tsqrt→T0] 3. Tf:=[Tx→T2] 4. Tnum4:=N 5. Tsqrt := [N → N] Equation 2: step 1: T1 is replaced by current substitution: [Tf* Tx -> T2] = [Tnum4* Tsqrt -> T0] Both side are composite, apply step 5: Equations are split and Eq2 is removed.

52 Type checking and inference
Using the type constraints approach Question 2 (cont’d): Typing the application ((lambda (f x) (f x)) 4 sqrt) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 2. T1:=[Tf*Tx→T2] T1:=[Tnum4*Tsqrt→T0] 3. Tf:=[Tx→T2] 4. Tnum4:=N 5. Tsqrt := [N → N] 6. Tf:=Tnum4 7. Tx:=Tsqrt 8. T2:=T0 Equation 2: step 1: T1 is replaced by current substitution: [Tf* Tx -> T2] = [Tnum4* Tsqrt -> T0] Both side are composite, apply step 5: Equations are split and Eq2 is removed.

53 Type checking and inference
Using the type constraints approach Question 2 (cont’d): Typing the application ((lambda (f x) (f x)) 4 sqrt) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 3. Tf:=[Tx→T2] T1:=[Tnum4*Tsqrt→T0] 4. Tnum4:=N 5. Tsqrt := [N → N] 6. Tf:=Tnum4 7. Tx:=Tsqrt 8. T2:=T0 Equation 3: step 1: No change. Eq3 is added to the substitution.

54 Type checking and inference
Using the type constraints approach Question 2 (cont’d): Typing the application ((lambda (f x) (f x)) 4 sqrt) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 4. Tnum4:=N T1:=[Tnum4*Tsqrt→T0] 5. Tsqrt := [N → N] Tf:=[Tx→T2] 6. Tf:=Tnum4 7. Tx:=Tsqrt 8. T2:=T0 Equation 3: step 1: No change. Eq3 is added to the substitution.

55 Type checking and inference
Using the type constraints approach Question 2 (cont’d): Typing the application ((lambda (f x) (f x)) 4 sqrt) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 4. Tnum4:=N T1:=[Tnum4*Tsqrt→T0] 5. Tsqrt := [N → N] Tf:=[Tx→T2] 6. Tf:=Tnum4 7. Tx:=Tsqrt 8. T2:=T0 Equation 4: step 1: No change. Eq4 is added to the substitution: Any occurrence of Tnum4 is substituted by N

56 Type checking and inference
Using the type constraints approach Question 2 (cont’d): Typing the application ((lambda (f x) (f x)) 4 sqrt) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 5. Tsqrt := [N → N] T1:=[N*Tsqrt→T0] 6. Tf:=Tnum4 Tf:=[Tx→T2] 7. Tx:=Tsqrt Tnum4:=N 8. T2:=T0 Equation 4: step 1: No change. Eq4 is added to the substitution: Any occurrence of Tnum4 is substituted by N

57 Type checking and inference
Using the type constraints approach Question 2 (cont’d): Typing the application ((lambda (f x) (f x)) 4 sqrt) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 5. Tsqrt := [N → N] T1:=[N*Tsqrt→T0] 6. Tf:=Tnum4 Tf:=[Tx→T2] 7. Tx:=Tsqrt Tnum4:=N 8. T2:=T0 Equation 5: step 1: No change. Eq5 is added to the substitution: Any occurrence of Tsqrt is substituted by [N→N]

58 Type checking and inference
Using the type constraints approach Question 2 (cont’d): Typing the application ((lambda (f x) (f x)) 4 sqrt) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 6. Tf:=Tnum4 T1:=[N*[N → N]→T0] 7. Tx:=Tsqrt Tf:=[Tx→T2] 8. T2:=T0 Tnum4:=N Tsqrt := [N → N] Equation 5: step 1: No change. Eq5 is added to the substitution: Any occurrence of Tsqrt is substituted by [N→N]

59 Type checking and inference
Using the type constraints approach Question 2 (cont’d): Typing the application ((lambda (f x) (f x)) 4 sqrt) STAGE-IV: Solving the equations. For each equation: Apply the current substitution to the equation (replace vars by their substituting expressions). Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. One side is a variable? Apply the equation to the substitution. Add the equation to the substitution. A circular substitution occurred? Output FAIL. Both side are composite with the same type constructor? Split into equations between corresponding components and add to the set of equations. Equation Substitution 6. Tf:=Tnum4 T1:=[N*[N → N]→T0] 7. Tx:=Tsqrt Tf:=[Tx→T2] 8. T2:=T0 Tnum4:=N Tsqrt := [N → N] Equation 6: step 1: Tf and Tnum4 are substituted: [Tx→T2]=N We get a conflicting equation and neither of the further steps is valid. THE EXPRESSION IS NOT WELL-TYPED.


Download ppt "Practice session #4: Static Type Correctness Algorithms:"

Similar presentations


Ads by Google