In this section we will investigate writing a program which makes extensive use of the ideas from the previous lesson on types. The program simulates a very simple calculator. The program will take a sequence of calculator commands and display the final content of memory. Each calculator command has an opcode, an integer value indicating the memory location involved, and an integer value. In this program there are three data types of interest.
Memory is a an array of integer values.
A program is a sequence of calculator commands. A calculator command has an opcode, a memory address, and a value operand. The last alias presupposes a definition for Command . Create a new file to contain the calculator program and enter these two type aliases. Since the program command combines several values into one command, we will make use of an algebraic type for its definition.