#Typing Philosophy
4 messages in this thread
The 2nd and 3rd editions have the same thing to say on this subject. If you
look at sect 9.1 of the report (page 152 2nd ed.), you'll see…
Operand types are said to be assignment compatible if either they are
compatible or both are INTEGER or CARDINAL or subranges with base types INTEGER
or CARDINAL.
and in sect 6.3 (page 146) …
A type T1 is said to be compatible with a type T0, if it is declared either as
T1 = T0 or as a subrange of T0, or if T0 is a subrange of T1, or if T0 and T1
are both subranges of the same (base) type.
He doesn't say they are compatible if T1 and T0 have the same structure. My
example does show that anonymous types aren't compatible: y is not the same as
z1 or z2 even though they have the same structure.
Your Cc and DD are compatible because as he says in sect 9.1 they are both of
TYPE INTEGER. The way I think of it is that the standard types have been
defined already and what you really have is something like …
TYPE
INTEGER = ——-;
CARDINAL = ——-;
CHAR = ——-;
etc.
VAR
Cc : INTEGER;
DD : INTEGER;
And therefore they are both defined using the same type rather than as two
separate anonymous types.
Tom
The best way to look at is is to not treat any ARRAY as a type but rather as a
variable description using a type.
Thanks for the instruction. I guess I'll just need to import more types. I
wish Wirth would go all the way and forbid one to declare variables without
pre-declaring a type; INTEGER, CHAR, CARD etc should only be legal inside the
TYPE section. Make me have
TYPE
Counter = CARD;
VAR
i : Counter;
and so forth. _That_ would keep me from adding apples and oranges!
Please don't suggest making M2 any more wordy than it already is. I've been
busy lately translating some more C -> M2 and have grown increasingly more
weary of the amount of code that must be created to accomplish C "things" in
M2. If anything I wish type checking could be somewhat relaxed.