Skip to main content Accessibility help
×
Hostname: page-component-5c6d5d7d68-ckgrl Total loading time: 0 Render date: 2024-08-13T00:26:38.814Z Has data issue: false hasContentIssue false

9 - Infinite lists

Published online by Cambridge University Press:  05 November 2014

Richard Bird
Affiliation:
University of Oxford
Get access

Summary

We have already met infinite lists in Chapter 4 and even given an induction principle for reasoning about them in Chapter 6. But we haven't really appreciated what can be done with them. In this chapter we want to explain in more detail exactly what an infinite list is, and how they can be represented by cyclic structures. We also describe another useful method for reasoning about infinite lists, and discuss a number of intriguing examples in which infinite and cyclic lists can be used to good effect.

Review

Recall that [m‥] denotes the infinite list of all integers from m onwards:

ghci> [1‥]

[1,2,3,4,5,6,7,{Interrupted}

ghci> zip [1‥] “hallo”

[(1,'h'),(2,'a'),(3,'l'),(4,'l'),(5,'o')]

It would take forever to print [1‥], so we interrupt the first computation. The second example illustrates a simple but typical use of infinite lists in finite computations.

In Haskell, the arithmetic expression [m‥] is translated into enumFrom m, where enumFrom is a method in the Enum class, and defined by

enumFrom :: Integer → [Integer]

enumFrom m = m:enumFrom (m+1)

Thus [m‥] is defined as an instance of a recursively defined function. The computation makes progress because (:) is non-strict in its second argument.

It is important to bear in mind that infinite lists in computing do not have the same properties as infinite sets do in mathematics.

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

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.

  • Infinite lists
  • Richard Bird, University of Oxford
  • Book: Thinking Functionally with Haskell
  • Online publication: 05 November 2014
  • Chapter DOI: https://doi.org/10.1017/CBO9781316092415.010
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.

  • Infinite lists
  • Richard Bird, University of Oxford
  • Book: Thinking Functionally with Haskell
  • Online publication: 05 November 2014
  • Chapter DOI: https://doi.org/10.1017/CBO9781316092415.010
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.

  • Infinite lists
  • Richard Bird, University of Oxford
  • Book: Thinking Functionally with Haskell
  • Online publication: 05 November 2014
  • Chapter DOI: https://doi.org/10.1017/CBO9781316092415.010
Available formats
×