Questions: Constraint-Based Type Checking

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A type checker processes `let f x = x + 1` with no type annotations. It assigns type variable α to x. What constraint does the `+` operation generate?

Aα = float, because + in most languages operates on floating-point numbers by default
Bα = int, because + requires operands of the same type and 1 is an integer literal, so x must also be int
CA type error, because x has no annotation and the checker cannot proceed without one
DNo constraint — type variables are left unresolved until the function is called with a concrete argument
Question 2 Multiple Choice

What is the key architectural advantage of separating constraint generation from constraint solving in type checking?

AIt makes type checking faster because constraints can be checked in parallel during lexical analysis
BIt allows the type system to be extended with new constraint forms (subtyping, trait bounds, refinements) without rewriting the core solver
CIt eliminates the need for garbage collection because type variables are automatically freed after constraint solving
DIt ensures that programs without explicit type annotations are always rejected, which improves code documentation
Question 3 True / False

Constraint-based type checking requires programmers to write explicit type annotations for nearly every function parameter and variable in order to generate constraints.

TTrue
FFalse
Question 4 True / False

In constraint-based type checking, unification finds the most general substitution that makes two type expressions equal, and reports a type error when no such substitution exists.

TTrue
FFalse
Question 5 Short Answer

Why does constraint-based type checking enable type inference for unannotated code, while traditional syntax-directed type checking does not?

Think about your answer, then reveal below.