9.5. Type Override

[19]TypeOverride::= Expression :!: Type  

While the typechecker can be helpful, it will not accept programs that are not typesafe according to its algorithm. This can be burdensome when the programmer knows that an expression will have a certain type but the typechecker cannot verify it.

Since the typechecker is optional, it can always be turned off in these cases. But this is often too drastic a solution: typechecking difficulties often arise from small segments of a much larger program, and the rest of the program still benefits from typechecking.

The typechecker may be selectively disabled for parts of a program. For this purpose, the typechecker allows an override of the type of an expression. Overriding is like adding type information to an expression, but rather than verifying that an expression has the stated type, the typechecker instead assumes that the stated type is correct, without examining the expression at all. Thus, the programmer can supply any type without being restricted by the typechecking algorithm.

This feature should be used sparingly, with the knowledge that it does compromise the integrity of the typechecking algorithm. If the supplied type is wrong, runtime type errors could propagate to any part of the program that depends on that type. Overrides are useful for rapid prototyping, but they are not recommended for production code.

9.5.1. Related Links

Related Reference Topics