This page was saved using WebZIP 7.0.2.1028 on 05/28/16 20:57:10.
Address: http://web.mit.edu/6.005/www/sp16/classes/16-recursive-data-types/
Title: Reading 16: Recursive Data Types  •  Size: 4148  •  Last Modified: Mon, 07 Mar 2016 00:59:45 GMT
6.005 — Software Construction
Spring 2016

Reading 16: Recursive Data Types

Software in 6.005

Safe from bugsEasy to understandReady for change
Correct today and correct in the unknown future. Communicating clearly with future programmers, including future you. Designed to accommodate change without rewriting.

Objectives

  • Understand recursive datatypes
  • Read and write datatype definitions
  • Understand and implement functions over recursive datatypes
  • Understand immutable lists and know the standard operations on immutable lists
  • Know and follow a recipe for writing programs with ADTs

Introduction

In this reading we’ll look at recursively-defined types, how to specify operations on such types, and how to implement them. Our main example will be immutable lists.

Then we’ll use another recursive datatype example, matrix multiplications, to walk through our process for programming with ADTs.

Part 1: Recursive Data Types

Part 2: Writing a Program with ADTs

Summary

Let’s review how recursive datatypes fit in with the main goals of this course:

  • Safe from bugs. Recursive datatypes allow us to tackle problems with a recursive or unbounded structure. Implementing appropriate data structures that encapsulate important operations and maintain their own invariants is crucial for correctness.

  • Easy to understand. Functions over recursive datatypes, specified in the abstract type and implemented in each concrete variant, organize the different behavior of the type.

  • Ready for change. A recursive ADT, like any ADT, separates abstract values from concrete representations, making it possible to change low-level code and high-level structure of the implementation without changing clients.