[   ^ to index...   |   next -->   ]

CSE 341 : 5 April 2001

A brief comment on types

What is the purpose of a type system?

My take: To ensure that every value is always used according to valid behaviors defined for that value. Type systems label values with "types", and then ensure that all actions performed on values of a given type are legal actions for that type.

A good static type system makes many common programming errors "illegal" in the language. Errors can be caught earlier (at load/compile time) and corrected with less effort. A program that is legal under a given type system is said to be well-typed.

What makes a (static) type system "bad" or "good"?

Absurd type system #1

In this type system, it is impossible to perform any illegal operation on any value. Furthermore, it is impossible to mingle values of inappropriate type.

Obviously, this type system is useless, because it is not permissive enough. That is, we cannot express any interesting programs. Here is another type system:

Absurd type system #2

This type system is useless as well, but for a different reason: a programmer can write anything, including ridiculously incorrect programs. The type system is not restrictive enough to express any useful properties. (Some people wouldn't even call this a type system.)

Hence, one important aspect of "good":

A good type system is expressive: it allows the programmer to write interesting legal programs, but also to check interesting properties and restrictions for these programs.


Keunwoo Lee
Last modified: Wed Apr 4 18:36:43 PDT 2001