CS 15-212: Fundamental Structures of Computer Science II

Lecture 14: References and State

The programming techniques used so far in the course have been, for the most part, "purely functional," although we have made some moderate use of exceptions for simple error handling. However many problems are most naturally addressed by keeping track of the "state" of an internal machine, which typically requires the use of mutable storage. ML supports mutable cells, or references, that store values of a fixed type. The value in a mutable cell can be initialized, read, and changed (mutated), and these operations result in effects that change the store. Programming with references is often carried out with the help imperative techniques, using functions solely for the way they change storage, rather than for their return values.

Key Concepts

Sample Code

Handout

On-line Notes


[ home | schedule | language | assignments | handouts ]

John Lafferty
lafferty@cs.cmu.edu