Professional Documents
Culture Documents
Type Systems: Soundness of A Programming Language
Type Systems: Soundness of A Programming Language
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