You are on page 1of 2

Type Systems

LUCA CARDELLI
Systems Research Center, Digital Equipment Corporation ^luca@src.dec.com&

The fundamental purpose of a type sys- ness has not been formally established.
tem is to prevent the occurrence of type Adequate technology, however, is now
errors during the execution of a pro- available. It involves defining the no-
gram. This informal statement moti- tion of type error for a given language,
vates the study of type systems but formalizing the type system by a set of
requires clarification. Its accuracy de- type rules, and verifying that program
pends, first of all, on the rather subtle execution of well-typed programs cannot
issue of what constitutes a type error. produce type errors. This process, if suc-
Even when that is settled, the type cessful, guarantees the type-soundness
soundness of a programming language of a language as a whole. Type-checking
(the absence of type errors in all pro- algorithms can then be developed as a
gram runs) is a non-trivial property. A separate concern, and their correctness
fair amount of careful analysis is re- can be verified with respect to a given
quired to avoid false and embarrassing type system; this process guarantees
claims of type soundness; as a conse- that typecheckers satisfy the language
quence, the classification, description, definition.
and study of type systems have emerged
as a formal discipline.
PROGRAM TYPES
The formal framework of type sys-
tems has practical applicability; it pro- A type system describes the types that
vides conceptual tools with which to can be used to annotate programs and
judge the adequacy of important aspects the relationship between programs and
of language definitions. Informal lan- types; common program types include
guage descriptions often fail to specify a Booleans, Integers, Reals, Records,
type system in sufficient detail to allow Unions, Arrays, Objects, and Proce-
unambiguous implementation: different dures. Annotations about the behavior
compilers for the same language may of programs can, in general, range from
implement slightly different type sys- informal comments to formal specifica-
tems. Moreover, many language defini- tions subject to theorem proving. Type
tions have been found to be type-un- systems sit in the middle of this spec-
sound, allowing a program to crash even trum: they are more precise than com-
though it is judged acceptable by a type- ments and more easily mechanizable
checker. Formal techniques need not be than full specifications.
applied in full to be useful; a knowledge Type systems are designed to be de-
of the main principles of type systems cidably verifiable: there should be an
can help to avoid obvious and not-so- algorithm (called a typechecking algo-
obvious pitfalls, and can inspire regu- rithm) that can tell whether or not a
larity and orthogonality in language de- program is type-correct (general specifi-
sign. cations do not have correctness algo-
For the great majority of program- rithms). Type systems should be trans-
ming languages, type systems have not parent: a programmer should be able to
been formally specified and type sound- predict easily whether a program will

Copyright © 1996, CRC Press.

ACM Computing Surveys, Vol. 28, No. 1, March 1996


264 • Luca Cardelli

typecheck. If it fails to typecheck, the judgments on the basis of other valid


reason for the failure should be self- judgments. In contrast to monolithic
evident (automatic theorem proving typechecking algorithms, type rules are
may fail in mysterious ways). Type sys- highly modular: rules for different pro-
tems should be enforceable: type decla- gram constructs can be written sepa-
rations should be statically checked as rately. Therefore, type rules are com-
much as possible, and otherwise dynam- paratively easy to read, understand,
ically checked. The consistency between analyze, and reuse.
type declarations and their associated A collection of type rules is called a
programs should be routinely verified (formal) type system. A program frag-
(program comments and conventions ment M is well-typed if there is a type A
are not checked). such that G£ M : A is a valid judgment
These considerations dictate the kind for some G; that is, if the program frag-
of constructions that are appropriate for ment M can be given some type. If there
typing programs. For example, they ex- is no possible type for a given program,
plain why many ordinary set-theoretical the program is not typeable (it has a
constructions are inappropriate, since type error). Thus, type errors are for-
they are not easily manipulated by a malized independently of any particular
typechecker. Type systems for program- typechecking algorithm.
ming languages take inspiration, in- Type systems are not explicitly algo-
stead, from type theory, which is a rithmic: the discovery of a type for a
branch of constructive logic separate term in a given type system is called the
from set theory. type inference problem. Its solution re-
quires the construction of appropriate
FORMAL TYPE SYSTEMS typechecking algorithms, which is in it-
Type systems are normally described self an important and sometimes com-
via a particular formalism based on as- plex endeavor.
sertions called judgments. The most im-
portant judgment is the typing judg-
ment, which asserts that a program STATUS AND OUTLOOK
fragment M has a type A with respect to A large variety of formal type systems
a typing environment for the free vari- have been developed, with correspond-
ables of M. This judgment is written in ing typechecking algorithms. They cover
the form: imperative, functional, and concurrent
G£M:A program M has languages. They can handle simple
type A in environ- and structured types, data abstraction,
ment G polymorphism, object-orientation, and
For example: modularization.
At the moment, some advanced con-
f £ true : Bool true has type Bool structions used in programming escape
in the empty envi- proper type-theoretical foundations.
ronment This could be either because the pro-
f,x:Int £ x 1 1 : Int x11 has type Int, gramming constructions are ill-con-
provided that x has ceived or because our type theories are
type Int not yet sufficiently expressive: only the
Any given judgment can be regarded future will tell. Examples of active re-
as valid (e.g., G£ true : Bool) or invalid search areas are the typing of advanced
(e.g. G£ true : Int). The collection of valid object-orientation and modularization
judgments is described via type rules, constructs, and the typing of concur-
which assert the validity of certain rency and distribution.

ACM Computing Surveys, Vol. 28, No. 1, March 1996

You might also like