# Class 26: Types (2)

Back to Types (1). On to Types (3).

Held: Wednesday, April 5, 2006

Summary: Today we continue our exploration of types.

Related Pages:

Assignments

• Read selected sections of Cardelli and Wegner.

Notes:

• Extra credit for attending today's talk on visualization.

Overview:

• Types, Revisited.
• Describing Types.
• Types as Sets, Revisited.
• References, Pointers, and Variables.
• Notes on Liskov et al.

## Types, Revisited

• Recall that we've been talking about types and type systems.
• We've found that there are (at least) three ways to think about types:
• A type describes a set of values.
• A type describes a collection of operations that can be performed on the values of the type.
• A type describes restrictions on the parameters to a function.
• If we think about types as sets of values, we might take advantage of some set operations to form new types. These include
• Subset (including same set).
• Intersection
• Union
• Product (cross). AxB = { <a,b> | a in A, b in B }
• Power set. 2A = { B | B is a subset of A }
• Self-product. An = A x A x ... x A (n times).
• Star (not standard set notation). A* = union (An)
• We've looked at some of these in terms of actual types.
• A record is like a product.

## Types in Practice

• We've also seen that, in practice, that are a variety of kinds of types.
• Languages provide primitive types, collections that support building blocks for further types.
• Languages may support compound types, ways to build new collections from the primitive types.
• Languages may support interfaces (abstract types), specifications on the capabilities of objects.
• Are there others?

## Types as Sets, Revisited

• We noted in class that, when we think of sets, we also think of the operations union, intersection, and difference.
• Are there reasons we'd want to use these in defining types?
• Are there languages that permit us to do so?

## References, Pointers, and Variables

• In many programming languages, we have another kind of type constructor used to build types: the pointer/reference.
• For example, elements of of the pointer to an integer type support:
• Dereference: get the integer.
• Reference: point to a different integer.
• Note that we might want to make a similar distinction between integer and integer variable.
• The latter supports assign while the former does not.
• This is a somewhat subtle distinction that many have trouble making. However, failure to make this distinction can lead to situations in which you treat integer constants as variables, leading to very strange results. (Yes, there were languages in which you could change the value of 2.)

## Notes on Liskov et al.

Back to Types (1). On to Types (3).

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 Wed May 10 09:02:59 2006.
The source to the document was last modified on Thu Jan 12 09:00:38 2006.
This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS302/2006S/Outlines/outline.26.html`.

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

Samuel A. Rebelsky, rebelsky@grinnell.edu