Skip to main content

Typechecker

rascal-0.34.0

Synopsis

Checks the type rules for a source language.

Description

A type system is a set of rules that defines how values, variables and functions may be used in a given programming languages.

A type checker, checks that these rules are enforced. The moment that type checking can be done differs per type system, but two extremes exist:

  • Static type checking: all checking is done before the program is executed.
  • Dynamic type checking: all checking is done during execution of the program.
  • Hybrid type checking: when possible checks are done before execution, the remaining checks are done during execution.

These different styles of type checking have different trade offs:

  • Static typechecking: Pro: most errors are found before execution. Con: more type declarations have to be written by the programmer and in some situations the type systems limits what can be expressed.
  • Dynamic checking: Pro: most flexible and expressive. Con: errors can only be found during execution.
  • Hybrid (or gradual) type checking: Pro: a reasonable compromise. Con not be as safe as full static typechecking.

Examples

  • In Java: If a variable has been declared as bool it cannot be added to an integer.
  • In Java: If a method has three formal parameters, it cannot be called with four actual parameters.
  • In Python: A variable can first get a string value assigned and later on an integer value.