Why is a type system described as improving program correctness rather than just documentation?
Think about your answer, then reveal below.
Model answer: A type system actively enforces constraints — the compiler or runtime rejects programs that violate them. Unlike comments or annotations, types are checked mechanically, so they catch real bugs (e.g., passing a string where an integer is expected) before the code runs. They serve as machine-verified specifications.
Types are often presented as documentation, but their real value is enforcement. When semantic analysis (the prerequisite) resolves names and scopes, the type checker then verifies that every operation is applied to compatible types. This catches a whole class of logical bugs at the earliest possible stage.