Type checking and inference

Slides:



Advertisements
Similar presentations
Letrec fact(n) = if zero?(n) then 1 else *(n, (fact sub1(n))) 4.4 Type Inference Type declarations aren't always necessary. In our toy typed language,
Advertisements

Finding angles with algebraic expressions
Solve an equation using subtraction EXAMPLE 1 Solve x + 7 = 4. x + 7 = 4x + 7 = 4 Write original equation. x + 7 – 7 = 4 – 7 Use subtraction property of.
Lesson 13.4 Solving Radical Equations. Squaring Both Sides of an Equation If a = b, then a 2 = b 2 Squaring both sides of an equation often introduces.
PPL Static Verification: Type Inference Lecture Notes: Chapter 2.
Type checking and inference Applications of typing axioms / rules are replaced with type equations. A solution to the equations assigns types for every.
The Equation Game. Why is an equation like a balance scale? 3 2x - 1 =
PPL Applicative and Normal Form Verification, Type Checking and Inference.
Solving Equations When do we use solving equations? We use solving equations methods when we know what the problem equals but not what the variable is.
Solve an equation using addition EXAMPLE 2 Solve x – 12 = 3. Horizontal format Vertical format x– 12 = 3 Write original equation. x – 12 = 3 Add 12 to.
Example 1 Solving Two-Step Equations SOLUTION a. 12x2x + 5 = Write original equation. 112x2x + – = 15 – Subtract 1 from each side. (Subtraction property.
Systems of Equations By Dr. Marinas. Solving Systems Graphing Method Substitution Method Elimination (or Adding) Method.
ALGEBRA TILES SOLVING EQUATIONS Replace the equation with tiles: Negative Positive -X X 1.
Solve Equations With Variables on Both Sides. Steps to Solve Equations with Variables on Both Sides  1) Do distributive property  2) Combine like terms.
Warm-up. Systems of Equations: Substitution Solving by Substitution 1)Solve one of the equations for a variable. 2)Substitute the expression from step.
6-2 SOLVING LINEAR SYSTEMS BY SUBSTITUTION Goal: Use substitution to solve a linear system Eligible Content: A / A
Solve a two-step equation by combining like terms EXAMPLE 2 Solve 7x – 4x = 21 7x – 4x = 21 Write original equation. 3x = 21 Combine like terms. Divide.
Type checking and inference Question 2: Typing the application (if #t (+ 1 2) 3) STAGE-I: Renaming ExpressionVariable (if #t (+ 1 2) 3) T0 (+ 1 2) T1 +
11.3 Solving Radical Equations Definitions & Rules Simplifying Radicals Practice Problems.
Solving Equations. An equation links an algebraic expression and a number, or two algebraic expressions with an equals sign. For example: x + 7 = 13 is.
PPL Leftovers: LET Syntax & Formal Semantics Static Verification: Type Inference Lecture Notes: Chapter 2.
Textbook pages 69 & 73 IAN pages 91 & 95. Each side of the equation must be balanced. We balance an equation by doing the same thing to both sides of.
SOLVING QUADRATIC EQUATIONS BY COMPLETING THE SQUARE
Type Correctness.
Today’s Learning Goals:
Solve for variable 3x = 6 7x = -21
Solving Systems Using Substitution
Type Inference using Type Constraints
Variables on Both Sides with Equations
One-Step Equations with Subtraction
Splash Screen.
3-2: Solving Systems of Equations using Substitution
Solving Division Equations.
Solving Equations by Factoring and Problem Solving
Solving Systems using Substitution
Solve a system of linear equation in two variables
3-2: Solving Systems of Equations using Substitution
Solving Systems of Equations using Substitution
What is an equation? An equation is a mathematical statement that two expressions are equal. For example, = 7 is an equation. Note: An equation.
3-2: Solving Systems of Equations using Substitution
USING GRAPHS TO SOLVE EQUATIONS
2 Understanding Variables and Solving Equations.
1.4 Solving Absolute-Value Equations
Practice session #4: Static Type Correctness Algorithms:
Solving Multi-Step Equations
Solving Multiplication and Division Equations
Solving One and Two Step Equations
6-2 Solving Linear Systems by substitution
Solving One Step Equations
Warm Up Solve. 1. 2x + 9x – 3x + 8 = –4 = 6x + 22 – 4x 3. + = 5
a + 2 = 6 What does this represent? 2 a
Solving a System of Equations in Two Variables by the Addition Method
Solving 1-Step Integer Equations
Solving Equations 3x+7 –7 13 –7 =.
Solving Equations with Variables on Both Sides
1.4 Solving Absolute-Value Equations
Solving Equations with Variables on Both Sides
3-2: Solving Systems of Equations using Substitution
Solving Equations Containing Rational Expressions § 6.5 Solving Equations Containing Rational Expressions.
Example 2B: Solving Linear Systems by Elimination
3-2: Solving Systems of Equations using Substitution
3-2: Solving Systems of Equations using Substitution
Algebra Revision.
Notes Over Using Radicals
One-Step Equations with Addition and Subtraction
3-2: Solving Systems of Equations using Substitution
3-2: Solving Systems of Equations using Substitution
The Substitution Method
Warm- Up: Solve by Substitution
Presentation transcript:

Type checking and inference Using the type constraints approach Question 3 (cont’d): Typing the application (lambda (x) (x x)) STAGE-II: Construct type equations. The rules: 1. Atomic expressions / primitive-procedures: Construct equations using their types. 2. Lambda expressions: For (lambda (v1 . . . vn) e1 . . .em), construct: 3. Application expressions: For (f e1 . . .en), construct: Expression Equation (lambda(x) (x x)) T0 = [Tx → T1 ] (x x) Tx = [Tx → T1 ] Expression Var (lambda(x) (x x)) T0 (x x) T1 x Tx

Type checking and inference Using the type constraints approach Question 3 (cont’d): Typing the application (lambda (x) (x x)) STAGE-III: Solving the equations. For each equation: Replace vars by their substituting expressions. Both sides of the eq. are atomic? If equal, ignore equation. Else, output FAIL. Both sides are different vars? Apply the equation to the current 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. Equation Substitution 1. T0 = [Tx → T1 ] 2. Tx = [Tx → T1 ] Equation 1: Initially, the substitution is empty. Step 1 is ignored. Eq1 is moved to the substitution.

Type checking and inference Using the type constraints approach Question 3 (cont’d): Typing the application (lambda (x) (x x)) STAGE-III: Solving the equations. For each equation: Replace vars by their substituting expressions. Both sides of the eq. are atomic? If equal, ignore equation. Else, output FAIL. Both sides are different vars? Apply the equation to the current 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. Equation Substitution 2. Tx = [Tx → T1 ] T0 := [Tx → T1 ] Equation 1: Initially, the substitution is empty. Step 1 is ignored. Eq1 is moved to the substitution.

Type checking and inference Using the type constraints approach Question 3 (cont’d): Typing the application (lambda (x) (x x)) STAGE-III: Solving the equations. For each equation: Replace vars by their substituting expressions. Both sides of the eq. are atomic? If equal, ignore equation. Else, output FAIL. Both sides are different vars? Apply the equation to the current 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. Equation Substitution 2. Tx = [Tx → T1 ] T0 := [Tx → T1 ] Equation 2: Apply step 1: No change. Eq2 is moved to the substitution.

Type checking and inference Using the type constraints approach Question 3 (cont’d): Typing the application (lambda (x) (x x)) STAGE-III: Solving the equations. For each equation: Replace vars by their substituting expressions. Both sides of the eq. are atomic? If equal, ignore eq. Else, output FAIL. Both side are different vars? Apply the equation to the current 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. Equation Substitution T0 := [[Tx → T1 ] → T1 ] Tx := [Tx → T1 ] Equation 2: We got a circular substitution: Tx := [Tx → T1 ]