O'Reilly logo

Thinking Functionally with Haskell by Richard Bird

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 9

Infinite lists

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.

9.1 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required