In
programming languages, a
type system is a collection of rules that assign a property called
type to various constructs a
computer program consists of, such as
variables,
expressions,
functions or
modules. The main purpose of a type system is to reduce possibilities for
bugs in computer programs by defining interfaces between different parts of a computer program, and then checking that the parts have been connected in a consistent way. This checking can happen statically (at
compile time), dynamically (at
run time), or as a combination of static and dynamic checking. Type systems have other purposes as well, such as enabling certain compiler optimizations, allowing for
multiple dispatch, providing a form of documentation, etc.