Question
IN ML : a. Ada must sometimes use the context of a function call to determine which overloaded definition to use. Consider the statemente :=
IN ML :
a. Ada must sometimes use the context of a function call to determine which overloaded definition to use. Consider the statemente := f(f(a,b), f(c, d)) in an Ada-like language. Give an example of a set of types for the overloaded function f that makes this statement ambiguous, even whenthe types of a, b, c, d, and e are known.
b.
Consider an unknown language with itneger and real types in which 1+2, 0+2, 1+2.0, and 0+2.0 are all legal expressions.
a. Explain how this could be the result of coercion, using no overloading
b. Explain how this could be the result of overloading, using no coercion.
c. Explain how this could result from a combination of overloading and coercion.
c.. Consider an unknown language with integer and string types in which 1+2*3 evaluates to 7, "1"+"2"+"3" evaluates to "123", "1"+2+3 evaluates to "123", and 1+"2"+"3" has a type error. Describe a system of precedence, associativity, overloading, and coercion that could account for this. In your system, what is the result of evaluating the expression "1"+ 2*3?
d.
Write an ML function definition for each of the following functions. Try to predict what polytype ML will infer for each funtion. Then check your prediction using the ML language system. What is the polytype determined by ML for each case?
a. f(x) = 1
b. f(g) = g(1)
c. f(g, x, y) = g(x, y)
d. f(g, x) = g(g(x))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started