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.
As we will see in our discussion of types, in most programming languages
one must regularly ask if two values of similar types are
Often, the question is whether a value of one type can be assigned to
another type (called
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.
Make a copy of
and make sure that it compiles. Remember that you may have to use Erdos,
our compute server, to run the Pascal compiler.
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.)
Experimentally determine which variables our Pascal compiler considers assignment equivalent.
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.
Perform similar experiments using array rather than records.
Monday, 14 October 2002 [Samuel A. Rebelsky]
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