A type system of a language is a system which associates one or more data types with each value calculated during program execution.
The main functions of type systems include:
- providing type safety: type systems prevent so-called type errors by ensuring that each operation receives arguments of the types for which it makes sense, for example, math operations don't receive string or array arguments;
- optimization: the types associated with the values can be used by the compiler to optimize handling these values, for example, choose the way to store them and the algorithms to process them;
- documentation: usage of certain data type can illustrate the programmer's intent;
- abstraction: usage of high-level data types allows the programmer to think about the values as high-level entities and not as a collection of bits.
The typing discipline of a language is defined by the nature of type constraints and the way they are evaluated and enforced. The typing discipline originates from practical issues of computer architecture, compiler implementation and language design.
Note that some terms in this object domain can have no commonly agreed-upon meaning and their usage in different articles can depend on the meaning implied by the author.