CSCI 461 - HW 5 & HW 6 Exam
Questions With 100% Verified Answers
(Refer to Exercise 1 on page 130 of the textbook) Consider an
unknown language with a left-associative + operator that is
overloaded to have the following types: int*real -> real. int*int ->
int, real*int -> real, and real*real -> real. Suppose that the variable i
has type int and the variable r has type real. For each + in each of
the following expressions, say which type of + is used:
a. i + r
b. i + r + i
c. i + (r + i) -
correct answer ✅a. i + r. int*real -> real
b. i + r + i. int*real -> real, real*int -> real
c. i + (r + i). i. int*real -> real, real*int -> real
(Refer to Exercise 2 on page 130 of the textbook) Ada must
sometimes use the context of a function call to determine which
overloaded definition to use. Consider the statement e := f(f(a,b),
f(c, d)) in an Ada-like language. Give an example of a set of types for
, CSCI 461 - HW 5 & HW 6 Exam
Questions With 100% Verified Answers
the overloaded function f that makes this statement ambiguous,
even when the types of a, b, c, d, and e are known. -
correct answer ✅For any two types x and y, if f has these types:
f1: x*x->y
f2: y*y->y
f3: x*x->x
and if the variables are typed like this:
a:x
b:x
c:x
d:x
e:y
then the statement is ambiguous, since the overloading can be
resolved in two ways:
e:=f2(f1(a,b),f1(c,d))
Questions With 100% Verified Answers
(Refer to Exercise 1 on page 130 of the textbook) Consider an
unknown language with a left-associative + operator that is
overloaded to have the following types: int*real -> real. int*int ->
int, real*int -> real, and real*real -> real. Suppose that the variable i
has type int and the variable r has type real. For each + in each of
the following expressions, say which type of + is used:
a. i + r
b. i + r + i
c. i + (r + i) -
correct answer ✅a. i + r. int*real -> real
b. i + r + i. int*real -> real, real*int -> real
c. i + (r + i). i. int*real -> real, real*int -> real
(Refer to Exercise 2 on page 130 of the textbook) Ada must
sometimes use the context of a function call to determine which
overloaded definition to use. Consider the statement e := f(f(a,b),
f(c, d)) in an Ada-like language. Give an example of a set of types for
, CSCI 461 - HW 5 & HW 6 Exam
Questions With 100% Verified Answers
the overloaded function f that makes this statement ambiguous,
even when the types of a, b, c, d, and e are known. -
correct answer ✅For any two types x and y, if f has these types:
f1: x*x->y
f2: y*y->y
f3: x*x->x
and if the variables are typed like this:
a:x
b:x
c:x
d:x
e:y
then the statement is ambiguous, since the overloading can be
resolved in two ways:
e:=f2(f1(a,b),f1(c,d))