Docsity

Type Checking and Subtyping in Object-Oriented Programming - Prof. Westley Weimer, Study notes of Programming Languages

Partial preview of the text

Download Type Checking and Subtyping in Object-Oriented Programming - Prof. Westley Weimer and more Study notes Programming Languages in PDF only on Docsity!

Type Type

Checking Checking

Passing Out Review Forms

Lecture Outline

  • (^) Typing Rules
  • (^) Typing Environments
  • (^) “Let” Rules
  • (^) Subtyping
  • (^) Wrong Rules

Example: 1 + 2

1 : Int 1 + 2 : Int ` 2 : Int

Type Checking Proofs

  • (^) Type checking proves facts e : T
    • (^) One type rule is used for each kind of expression
  • (^) In the type rule used for a node e
    • (^) The hypotheses are the proofs of types of e’s subexpressions
    • (^) The conclusion is the proof of type of e itself

Rules for Constants

` false : Bool

[Bool]

` s : String

[String] (s is a string constant)

Two More Rules

` not e : Bool

` e : Bool

[Not]

` while e

1

loop e

2

pool : Object

` e

1

: Bool

` e

2

: T

[Loop]

Typing: Example

  • (^) Typing for while not false loop 1 + 2 * 3 pool while loop pool

Typing: Example

  • (^) Typing for while not false loop 1 + 2 * 3 pool while loop pool not false : Bool

Typing: Example

  • (^) Typing for while not false loop 1 + 2 * 3 pool while loop pool not false

: Bool : Bool

Typing: Example

  • (^) Typing for while not false loop 1 + 2 * 3 pool while loop pool not false

: Bool 1 : Bool : Int

Typing: Example

  • (^) Typing for while not false loop 1 + 2 * 3 pool while loop pool not false

1

2 : Bool : Bool : Int

Typing: Example

  • (^) Typing for while not false loop 1 + 2 * 3 pool while loop pool not false

1

2 3 : Bool : Bool : Int : Int

Typing: Example

  • (^) Typing for while not false loop 1 + 2 * 3 pool while loop pool not false

1

2 3 : Bool : Bool : Int : Int : Int