There are two standard ways to determine whether two types are
considered the same:
- Name equivalence
- Structural equivalence.
There can be many differences between the name equivalence and
structure equivalence.
Some of them are as follows:
Name equivalence:
- It is the simplest type. Two types are equal if, and only if,
they have the same name.
- The meaning of basic operations such as assignment operator
(denoted by "=" in C language) is specified in a language
definition.
- For example, the meaning of statements such as
variableA = variableB;
here the value of object y is copied into the memory locations for
variable x.
Structural equivalence:
- By using structural equivalence, two different types are equal
only if, they have the same structure which we may implement in
different ways.
- For this type of equivalence, the basic requirement is that
they have the same component type in the same order.
- Using structural equivalence the two types
Stack and Set
would be considered equivalent, which means that a translator would
accept statements such as
stackA = setA
Please let me know in the comments in case of any
confusion. Also, please upvote if you like.