v6 Semantics: static types on a dynamic runtime
Lesson, slides, and applied problem sets.
View SlidesLesson
v6 Semantics: type checking
This stage enforces static types before code generation.
Core checks
- every expression has a type
- assignments are type-compatible
- function calls match param types
- returns match declared return type
Inference rules
let x = 1;infersnumberlet xs = [];is an error (needs annotation)
Type errors (examples)
let x: number = "hi";=> type mismatchtrue + 1=> invalid operandsfn f(a: number) -> number { return "x"; }=> return type mismatch
Collections
- arrays are homogenous
- maps have consistent key/value types
- map keys must be number/bool/string