In Hindley-Milner type inference, what does the occurs check in unification prevent, and what happens if it is omitted?
Correct! Well done.
Incorrect.
The correct answer is D) It prevents a type variable from being unified with a type expression that contains that same variable, which would otherwise build an infinite (cyclic) type and cause the algorithm to loop forever or produce an inconsistent substitution
Correct Answer
It prevents a type variable from being unified with a type expression that contains that same variable, which would otherwise build an infinite (cyclic) type and cause the algorithm to loop forever or produce an inconsistent substitution
Unifying a with a -> a would require a to equal a function whose argument is itself, an infinite type with no finite representation. The occurs check rejects such unifications; skipping it (as some implementations do for performance) can cause non-termination or unsound "infinite type" results.