Programming Languages (CS302 2006S)
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[CSC302 1999S]
Back to Types (2). On to Declarative Langauges.
Held: Friday, April 7, 2006
Summary: Today we conclude our exploration of types by exploring notions of type equivalence.
Related Pages:
Notes:
return homework and distribute examday.
Overview:
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]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[CSC302 1999S]
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.27.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby