Book contents
- Frontmatter
- Contents
- Preface
- 1 Predicate Logic
- 2 The Simple Imperative Language
- 3 Program Specifications and Their Proofs
- 4 Arrays
- 5 Failure, Input-Output, and Continuations
- 6 Transition Semantics
- 7 Nondeterminism and Guarded Commands
- 8 Shared-Variable Concurrency
- 9 Communicating Sequential Processes
- 10 The Lambda Calculus
- 11 An Eager Functional Language
- 12 Continuations in a Functional Language
- 13 Iswim-like Languages
- 14 A Normal-Order Language
- 15 The Simple Type System
- 16 Subtypes and Intersection Types
- 17 Polymorphism
- 18 Module Specification
- 19 Algol-like Languages
- Appendix: Mathematical Background
- Bibliography
- Index
16 - Subtypes and Intersection Types
Published online by Cambridge University Press: 28 January 2010
- Frontmatter
- Contents
- Preface
- 1 Predicate Logic
- 2 The Simple Imperative Language
- 3 Program Specifications and Their Proofs
- 4 Arrays
- 5 Failure, Input-Output, and Continuations
- 6 Transition Semantics
- 7 Nondeterminism and Guarded Commands
- 8 Shared-Variable Concurrency
- 9 Communicating Sequential Processes
- 10 The Lambda Calculus
- 11 An Eager Functional Language
- 12 Continuations in a Functional Language
- 13 Iswim-like Languages
- 14 A Normal-Order Language
- 15 The Simple Type System
- 16 Subtypes and Intersection Types
- 17 Polymorphism
- 18 Module Specification
- 19 Algol-like Languages
- Appendix: Mathematical Background
- Bibliography
- Index
Summary
Many programming languages provide a variety of implicit conversions (sometimes called “coercions”) that serve to make programs more succinct; the most widespread example is the conversion of integers to real (floating-point) numbers. In modern type systems, such conversions are captured by the concept of subtyping.
In this chapter, we extend the simple type system by introducing a subtype relation ≤ between types. When θ ≤ θ′, we say that θ is a subtype of θ′ or, occasionally, that θ′ is a supertype of θ. Syntactically, this relationship implies that any expression of type θ is also an expression of type θ′, and thus can be used in any context that permits an expression of type θ′. In extrinsic semantics, the relationship implies that the set denoted by θ is a subset of that denoted by θ′, and that values which are equivalent for the type θ are also equivalent for θ′; more simply, the partial equivalence relation for θ must be a subset of the partial equivalence relation for θ′. In intrinsic semantics, θ ≤ θ′ implies that there is an implicit conversion function from the meaning of θ to the meaning of θ′.
We will also introduce intersection types, which permit the description of values with more than one conventional type. In extrinsic semantics, the intersection of types is modelled by the intersection of partial equivalence relations, and in intrinsic semantics by a constrained product.
We will find that both extrinsic and intrinsic semantics clarify the subtle interactions between subtypes and generic operators.
- Type
- Chapter
- Information
- Theories of Programming Languages , pp. 349 - 378Publisher: Cambridge University PressPrint publication year: 1998