Questions: Polymorphism and Type Variables

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

Inside a polymorphic function `reverse : ∀α. List α → List α`, what operations on the elements of type α can the function legally perform?

AAny operation, because the function will be type-checked at each call site with a concrete type
BOnly operations defined for all types — the function can rearrange elements but cannot inspect, compare, or compute with their values
CAny operation that the most common concrete type (e.g., Int) supports
DOperations determined at runtime by inspecting the actual type of α
Question 2 Multiple Choice

A team is choosing between Java-style type erasure and C++/Rust-style monomorphization for compiling a generic container library. Which tradeoff is correct?

AMonomorphization produces smaller binaries because it avoids storing type information at runtime
BType erasure produces faster code because it avoids boxing overhead, while monomorphization uses more memory
CMonomorphization produces faster, specialized code but larger binaries; type erasure produces smaller binaries but may incur boxing overhead
DBoth approaches produce identical machine code; the difference is only in compile-time checking
Question 3 True / False

Parametric polymorphism can be fully enforced at compile time — no runtime type inspection is required to maintain type safety.

TTrue
FFalse
Question 4 True / False

A type variable like `α` in `identity : ∀α. α → α` is essentially just a placeholder for 'any type' — the function can be specialized to perform type-specific operations when called with a concrete type.

TTrue
FFalse
Question 5 Short Answer

Why can a parametrically polymorphic function `identity : ∀α. α → α` not simply add 1 to its argument, even if every actual call site passes an integer?

Think about your answer, then reveal below.