Anonymous user
Type compatibility: Difference between revisions
no edit summary
(Created) |
No edit summary |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1:
[[Category:
* by name (nominal equivalence);
* by structure (structural equivalence).
In a more general context
A structural matching is necessarily based on
==Nominal equivalence example (in [[Ada]])==
<lang ada>
type Integer_1 is range 1..20;
type Integer_2 is range 1..20;
Line 14:
X : Integer_1 := 1;
Y : Integer_2 := X; -- Type error
</
Integer_1 does not match Integer_2 though both types have equivalent sets of values and operations.
==Structural equivalence example (in [[Ada]])==
<lang ada>
X : access String := new String'("ABC");
Y : not null access String := X; -- This is OK
</
The anonymous type of X matches the anonymous type of Y. The structure of both types is the same: "a pointer to String". Further, the constraint ''not null'' put on the type of Y does not effect equivalence because it is also structural.
|