13. [9-3 *3 points] (From Problem 8.15, p.46) First, read the problem descriptio
ID: 3716847 • Letter: 1
Question
13. [9-3 *3 points] (From Problem 8.15, p.46) First, read the problem description; it discusses a possible framework for determining structural equality when you include records, pointers, and recursive types. Now consider the following algorithm for determining structural equality relationships within a set of types. . Define two types to be equivalent at level 0 if (a) They're the same primitive type (int, double, etc.), (b) Or they're both record types with the same sequences of field names (regardless of the types of the fields), or (c) Or they're both pointer types (regardless of the types of things they point to). Define two types to be equivalent at level k+1 if they are equivalent at level k and (a) If they're both pointer types, the types they point to must be equivalent at level k or (b) If they're both record types, then each corresponding pair of fields must be equivalent at level k. Let's allow the abbreviation for "equivalent at level 0", for "equivalent at level 1", etc. Then some examples: int?double; int *-o double *, and int * double * (because int-o double). The two types discussed in the problem (rewritten into C-like syntax) are type A struct { struct B *x; double y; }; type Bstruct f struct A *double y; ; (a) Using the algorithm described above, are types A and B? Are they 1? (b) Given a set of types, how many levels do you have to use to determine equivalence of an arbitrary pair of types from the set? Do you think this algorithm meets the criteria given in the problem? Briefly explain. (c)Explanation / Answer
Type A and Type B are 0 equivalent because they are of the same primitive types.
They are also 1 equivalent because they are 0 equivalent and points to the same primitive types.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.