FUNCTIONAL PEARL: Enumerating the rationals
Jeremy Gibbons, David Lester and Richard Bird
Abstract
Every lazy functional programmer knows about the following approach to enumerating the positive rationals: generate a two-dimensional matrix (an infinite list of infinite lists), then traverse its finite diagonals (an infinite list of finite lists). Each row of the matrix has the positive rationals with a given denominator, and each column those with a given numerator: