Questions: Unification Algorithm

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A type inference engine tries to unify the type expression `α → β` with `Int → Bool`. What is the result?

AFailure — the arrow type constructor cannot be unified with other constructors
BThe substitution {α → Int, β → Bool}, making both expressions identical
CThe substitution {α → Bool, β → Int}, since type variables are symmetric
DSuccess with no substitution — arrow types are always compatible
Question 2 Multiple Choice

A programmer writes a function where, accidentally, the return type depends on itself — the function returns a list of its own return type. What does the unification algorithm do when it encounters the constraint unifying `α` with `List<α>`?

ASucceeds and infers the type `List<List<List<...>>>` as the return type
BFails immediately with a type error, because no finite substitution can satisfy this constraint
CSucceeds only if the list is empty, since an empty list has no elements to cause the cycle
DSkips the constraint and continues with remaining constraints in the program
Question 3 True / False

The occurs check in unification is an optional optimization — skipping it makes unification faster, and in practice, recursive types rarely arise in real programs.

TTrue
FFalse
Question 4 True / False

Unifying two compound types with different constructors — for example, `List<Int>` with `Pair<Int, Bool>` — always fails, even if their component types are compatible.

TTrue
FFalse
Question 5 Short Answer

Explain why the occurs check is necessary in unification and what specific error it prevents.

Think about your answer, then reveal below.