# Lab: Type Checking

## Preliminaries

Summary: In today's lab, you will explore type equivalence in the Pascal programming language.

Collaboration: Feel free to work on this lab in pairs or trios.

Turning It In: Save your answers in a plain text file and submit it using the ECA.

Grading: I expect that you will gain more from doing this lab than from me grading this lab. I may simply scan through your answers to see if you had any particularly valuable insights.

Useful Files:

## Background

As we will see in our discussion of types, in most programming languages one must regularly ask if two values of similar types are equivalent. Often, the question is whether a value of one type can be assigned to another type (called assignment equivalence).

One particularly interesting area in which to consider type equivalence is that of records. In the abstract, one might argue that since records are simply set products, any two records that have the same field types should be equivalent. In practice, we might also take naming and ordering of fields into account. We might even take the extreme view that any two types with different names are different, since the programmer clearly intended them to be different.

Consider the sample Pascal file, which defines variables using approximately nine variants on the same record type (one likely to be used for a point on the plane). Different people will have different intuitions as to which pairs of values should be considered equal. As language designer, you should make and document appropriate choices. As language implementor, you should determine what choices the language normally makes.

## Exercises

### Exercise 0: Preparation

Make a copy of `records.p` and make sure that it compiles. Remember that you may have to use Erdos, our compute server, to run the Pascal compiler.

### Exercise 1: Language Design

Decide which assignments you would and would not allow for each pair of variables in `records.p`. (You need not list all of them; simply think about some interesting ones.)

### Exercise 2: Experimental Equivalence

Experimentally determine which variables our Pascal compiler considers assignment equivalent.

### Exercise 3: Types in Other Places

Design a program that lets you test call equivalence; that is, your program should allow us to determine whether we can call a procedure that expects value of type t using a value fo type v.

### Exercise 4: Array Equivalence

Perform similar experiments using array rather than records.

## History

Monday, 14 October 2002 [Samuel A. Rebelsky]

• Created. The code was taken from last year's lab. The narrative is all new.

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Tue Dec 10 08:53:31 2002.
The source to the document was last modified on Mon Oct 14 15:01:51 2002.
This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS362/2002F/Labs/lab.07.html`.

You may wish to validate this document's HTML ; ; Check with Bobby

Glimmer Labs: The Grinnell Laboratory for Interactive Multimedia Experimentation & Research
glimmer@grinnell.edu