Typechecking - Inference & Equivalence
Inference: What type is that? See what type the variable of function was declared to have.
Equivalence: Are the two types the same?
- Nominal: same type name (e.g. Java)
- Structural: same formal type, i.e. same content and same content's order
Typechecking - Equivalence
How to test for norminal v.s. structural equivalence?
class A : int * string
class B : int * string
For static typed programming languages:
A* x = new B(); // x : NULL + Ref(A)
// or
A x = B(); // x : A
// Success means structrual
For dynamic typed programming languages:
x = A(); // x : A or x : NULL + Ref(A)
if x instanceOf B ... // Success means structrual