Questions: Hindley-Milner Type System

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A programmer writes `let f = fun x -> x in (f 5, f "hello")`. Which best explains why this typechecks in HM?

Af has type int when applied to 5 and type string when applied to 'hello', showing HM supports runtime type dispatch
BThe let binding generalizes f to ∀α. α → α, so each use independently instantiates α as int or string
CHM generates two separate monomorphic copies of f at compile time for each use site
DType inference fails here and the programmer must add an explicit type annotation
Question 2 Multiple Choice

Why can HM infer all types in a program while System F (arbitrary-rank polymorphism) cannot?

ASystem F allows side effects that interact with types in ways the inference algorithm cannot predict
BHM restricts universal quantifiers to the outermost level (prenex polymorphism), keeping inference decidable
CSystem F uses a larger set of type variables that causes the unification algorithm to loop indefinitely
DHM only supports type inference for programs without recursive functions
Question 3 True / False

In Hindley-Milner, a let-bound identifier can be used at different types in different parts of the program.

TTrue
FFalse
Question 4 True / False

Adding explicit type annotations to nearly every function in an HM-typed program allows the type checker to accept programs that inference alone would reject.

TTrue
FFalse
Question 5 Short Answer

Explain why the `let` binding plays a special role in HM generalization, and what would go wrong if HM tried to generalize type variables inside every lambda abstraction instead.

Think about your answer, then reveal below.