Skip to main content Accessibility help
×
Hostname: page-component-7bb8b95d7b-l4ctd Total loading time: 0 Render date: 2024-09-29T03:24:07.389Z Has data issue: false hasContentIssue false

23 - Subtyping

from Part VIII - Subtyping

Published online by Cambridge University Press:  05 February 2013

Robert Harper
Affiliation:
Carnegie Mellon University, Pennsylvania
Get access

Summary

A subtype relation is a preorder (reflexive and transitive relation) on types that validates the subsumption principle:

If τ′ is a subtype of τ, then a value of type τ′ may be provided whenever a value of type τ is required.

The subsumption principle relaxes the strictures of a type system to permit values of one type to be treated as values of another.

Experience shows that the subsumption principle, although useful as a general guide, can be tricky to apply correctly in practice. The key to getting it right is the principle of introduction and elimination. To determine whether a candidate subtyping relationship is sensible, it suffices to consider whether every introductory form of the subtype can be safely manipulated by every eliminatory form of the supertype. A subtyping principlemakes sense only if it passes this test; the proof of the type safety theorem for a given subtyping relation ensures that this is the case.

A good way to get a subtyping principle wrong is to think of a type merely as a set of values (generated by introductory forms) and to consider whether every value of the subtype can also be considered to be a value of the supertype. The intuition behind this approach is to think of subtyping as akin to the subset relation in ordinary mathematics. But, as we subsequently see, this can lead to serious errors, because it fails to take account of the eliminatory forms that are applicable to the supertype.

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2012

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Subtyping
  • Robert Harper, Carnegie Mellon University, Pennsylvania
  • Book: Practical Foundations for Programming Languages
  • Online publication: 05 February 2013
  • Chapter DOI: https://doi.org/10.1017/CBO9781139342131.024
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Subtyping
  • Robert Harper, Carnegie Mellon University, Pennsylvania
  • Book: Practical Foundations for Programming Languages
  • Online publication: 05 February 2013
  • Chapter DOI: https://doi.org/10.1017/CBO9781139342131.024
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Subtyping
  • Robert Harper, Carnegie Mellon University, Pennsylvania
  • Book: Practical Foundations for Programming Languages
  • Online publication: 05 February 2013
  • Chapter DOI: https://doi.org/10.1017/CBO9781139342131.024
Available formats
×