Skip to main content Accessibility help
×
Hostname: page-component-77c89778f8-7drxs Total loading time: 0 Render date: 2024-07-16T13:46:36.681Z Has data issue: false hasContentIssue false

2 - Data Structures

Published online by Cambridge University Press:  05 June 2012

Guy Cousineau
Affiliation:
Ecole Normale Supérieure, Paris
Michel Mauny
Affiliation:
Institut National de Recherche en Informatique et en Automatique (INRIA), Rocquencourt
Get access

Summary

Programs have to handle highly varied objects organized into categories, such as numbers, text, images, formulas, as well as other programs. These objects are for the most part foreign to the world of programming and involve quite diverse formal systems.

For each such category of objects, the programmer must define a representation in the objects of the programming language that he or she is using. This representation must satisfy criteria such as efficiency (by exploiting what the programmer has learned about algorithms) and clarity; that is, the way the data is structured should reflect the structure of the objects being represented. Representation of objects from the exterior world should not be some obscure encoding; rather, the conceptual, external structure should remain apparent.

In a typed language like Caml, the nature of an object lies in its type. It is thus natural to ask that the external structure of the objects being handled should be reflected in the types of their internal representation. For that purpose, the programmer must have the means to define a great variety of types.

In this chapter, we present the two principal type constructions that Caml offers: records and sums with constructors. You might think of a record as the product of named components, and a sum as the union of named components.

Record or Named Cartesian Products

Let's assume that we want to write programs working on complex numbers. We can imagine representing complex numbers by pairs (r,i) of type (float * float) giving the real and imaginary parts of such numbers.

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

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.

  • Data Structures
  • Guy Cousineau, Ecole Normale Supérieure, Paris, Michel Mauny, Institut National de Recherche en Informatique et en Automatique (INRIA), Rocquencourt
  • Translated by K. Callaway
  • Book: The Functional Approach to Programming
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9781139173018.005
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.

  • Data Structures
  • Guy Cousineau, Ecole Normale Supérieure, Paris, Michel Mauny, Institut National de Recherche en Informatique et en Automatique (INRIA), Rocquencourt
  • Translated by K. Callaway
  • Book: The Functional Approach to Programming
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9781139173018.005
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.

  • Data Structures
  • Guy Cousineau, Ecole Normale Supérieure, Paris, Michel Mauny, Institut National de Recherche en Informatique et en Automatique (INRIA), Rocquencourt
  • Translated by K. Callaway
  • Book: The Functional Approach to Programming
  • Online publication: 05 June 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9781139173018.005
Available formats
×