Programming Languages (CS302 2007S)
[Skip to Body]
Admin:
[Front Door]
[Glance]
[Handouts]
[Honesty]
Current:
[Current Outline]
[Current EBoard]
[Current Homework]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Outlines]
[Readings]
[Reference]
[HOG]
Misc:
[SamR]
[CSC302 1999S]
[CSC302 2006S]
Back to Types (2). On to Declarative Langauges.
This outline is also available in PDF.
Held: Friday, April 20, 2007
Summary: Today we conclude our exploration of types by considering two key eradings and exploring some notions of type equivalence.
Related Pages:
Overview:
Static typing is a useful property, but the requirement that all variables and expressions are bound to a type at compile time is sometimes too restrictive.Can you give an example of static typing being too restrictive?
appropriateplaces.
eqv?
in Scheme requires
some careful consideration of when functions or pairs are equivalent.
type xy = record x: integer; y: real; end; xy_alias = xy; ab = record a: integer; b: real; end; yx = record y: real; x: integer; end; abc = record a: integer; b: real; c: real; end; intrec = record x: integer; end; iarr = array[1..10] of integer; iare = array[2..11] of integer; var rec1: xy; rec2: xy_alias; rec3: ab; rec4: abc; rec5,rec6: record a: integer; b: real; end; rec7: record a: integer; b: real; end; rec8: yx; rec9: intrec; rec10: xy; arr1: iarr; arr2: iare; arr3,arr4: array[1..10] of integer; arr5: array[1..10] of integer;
rec1
and rec3
are structurally equivalent as
they are both pairs of (integer,real).
rec1
and rec8
are not structurally equivalent,
as they order their elements differently.
rec1
and rec3
are not structurally
equivalent under naming as they name their pairs differently.
rec3
and rec6
are structurally equivalent
under naming.
rec1
and rec2
are not name equivalent.
rec1
and rec10
are name equivalent.
realequivalence, it may be difficult to determine in the presence of pointers (explicit or implicit) and inclusion.
type alpha = record i1: integer; i2: integer; end; aardvark = record i1: integer; i2: integer; beta = record i: integer; a: alpha; end; bandicoot = record i: integer; a: aardvark; end;
alpha
and aardvark
are clearly equivalent.
Are beta
and bandicoot
? How do you tell?
type listp = pointer to list; list = record i: integer; next: listp; end; lstp = pointer to lst; lst = record i: integer; next: lstp; end;
type gammap = pointer to gamma; deltap = pointer to delta; gamma = record i: integer; next: deltap; end; delta = record i: integer; next: gammap; end;
More generaltypes to
less generaltypes? (E.g., real to int.)
Less generaltypes to
more generaltypes? (E.g., int to real.)
3 + "4"
in languages that can convert strings to integers.
ab
and abc
above.
what isin type systems, we might also reflect on
what might be.
base typesin our system.
Back to Types (2). On to Declarative Langauges.
[Skip to Body]
Admin:
[Front Door]
[Glance]
[Handouts]
[Honesty]
Current:
[Current Outline]
[Current EBoard]
[Current Homework]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Outlines]
[Readings]
[Reference]
[HOG]
Misc:
[SamR]
[CSC302 1999S]
[CSC302 2006S]
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 Sun Apr 29 11:26:43 2007.
The source to the document was last modified on Tue Jan 16 13:34:44 2007.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS302/2007S/Outlines/outline.33.html
.
You may wish to
validate this document's HTML
;
;
Check with Bobby