Skip to main content Accessibility help
×
Hostname: page-component-76fb5796d-45l2p Total loading time: 0 Render date: 2024-04-26T22:47:25.868Z Has data issue: false hasContentIssue false

14 - Generic Programming

from Part IV - Finite Data Types

Published online by Cambridge University Press:  05 February 2013

Robert Harper
Affiliation:
Carnegie Mellon University, Pennsylvania
Get access

Summary

Many programs can be seen as instances of a general pattern applied to a particular situation. Very often the pattern is determined by the types of the data involved. For example, in Chapter 9 the pattern of computing by recursion over a natural number is isolated as the defining characteristic of the type of natural numbers. This concept will itself emerge as an instance of the concept of type-generic, or just generic, programming.

Suppose that we have a function f of type ρρ′ that transforms values of type ρ into values of type ρ′. For example, f might be the doubling function on natural numbers. We wish to extend f to a transformation from type [ρ/t]τ to type [ρ′/t]τ by applying f to various spots in the input where a value of type τ occurs to obtain a value of type ρ′, leaving the rest of the data structure alone. For example, τ might be bool × ρ, in which case f could be extended to a function of type bool × ρ → bool × ρ′ that sends the pairs ⟨a, b⟩ to the pair ⟨a, f(b)⟩.

This example glosses over a significant problem of ambiguity of the extension. Given a function f of type ρρ′, it is not obvious in general how to extend it to a function mapping [ρ/t]τ to [ρ′/t]τ.

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.

  • Generic Programming
  • 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.015
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.

  • Generic Programming
  • 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.015
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.

  • Generic Programming
  • 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.015
Available formats
×