Book contents
- Frontmatter
- Contents
- Preface
- Part 1 Functions and Foundations
- Part 2 Procedures, Types, Memory Management, and Control
- 5 The Algol Family and ML
- 6 Type Systems and Type Inference
- 7 Scope, Functions, and Storage Management
- 8 Control in Sequential Languages
- Part 3 Modularity, Abstraction, and Object-Oriented Programming
- Part 4 Concurrency and Logic Programming
- Appendix A Additional Program Examples
- Glossary
- Index
6 - Type Systems and Type Inference
from Part 2 - Procedures, Types, Memory Management, and Control
Published online by Cambridge University Press: 05 June 2012
- Frontmatter
- Contents
- Preface
- Part 1 Functions and Foundations
- Part 2 Procedures, Types, Memory Management, and Control
- 5 The Algol Family and ML
- 6 Type Systems and Type Inference
- 7 Scope, Functions, and Storage Management
- 8 Control in Sequential Languages
- Part 3 Modularity, Abstraction, and Object-Oriented Programming
- Part 4 Concurrency and Logic Programming
- Appendix A Additional Program Examples
- Glossary
- Index
Summary
Programming involves a wide range of computational constructs, such as data structures, functions, objects, communication channels, and threads of control. Because programming languages are designed to help programmers organize computational constructs and use them correctly, many programming languages organize data and computations into collections called types. In this chapter, we look at the reasons for using types in programming languages, methods for type checking, and some typing issues such as polymorphism, overloading, and type equality. A large section of this chapter is devoted to type inference, the process of determining the types of expressions based on the known types of some symbols that appear in them. Type inference is a generalization of type checking, with many characteristics in common, and a representative example of the kind of algorithms that are used in compilers and programming environments to determine properties of programs. Type inference also provides an introduction to polymorphism, which allows a single expression to have many types.
TYPES IN PROGRAMMING
In general, a type is a collection of computational entities that share some common property. Some examples of types are the type int of integers, the type int→int of functions from integers to integers, and the Pascal subrange type [1 ‥ 100] of integers between 1 and 100. In concurrent ML there is the type int channel of communication channels carrying integer values and, in Java, a hierarchy of types of exceptions.
- Type
- Chapter
- Information
- Concepts in Programming Languages , pp. 129 - 161Publisher: Cambridge University PressPrint publication year: 2002