15-212: Principles of Programming

Lecture 18: Streams and Demand-Driven Computation

Functions in ML are evaluated eagerly, meaning that the arguments are reduced before the function is applied. An alternative is for function applications and constructors to be evaluated in a lazy manner, meaning expressions are evaluated only when their values are needed in a further computation. Lazy evaluation can be implemented by "suspending" computations in function values. This style of evaluation is essential when working with potentially infinite data structures, such as streams, which arise naturally in many applications. Streams are lazy lists whose values are determined by suspended computations that generate the next element of the stream only when forced to do so.

Key Concepts

Sample Code

On-line Notes by Robert Harper


Suggested Reading in Programming in Standard ML:


[ CS 15-212 Home page | schedule | language | assignments | handouts ]


Michael Erdmann