Some possibilities for questions1. The author states "Usually there are two separate grammars.
One says how to construct a sequence of tokens from a file of characters One says how to construct a parse tree from a sequence of tokens" Explain
how this implies that there are two separate passes by a compiler and what those passes are named
2. I've read that the binding time for the location in memory of a local variable in a recursive function is at run time. Explain why this is the case. Also explain
whether the binding time would be different if the function were not recursive.
3. I've read that the binding time for the type of a function's formal parameters is load time. Explain whether that is a correct statement.
4. Explain the notion of type equivalence making your explanation specific to either C++, Java, or ML. Include the definitions of name equivalence and
structural equivalence and which, if either, is used in the language.
5. The author of the text states "A key question for type systems: how much of the representation is exposed?" Explain why that is the case
and include examples form two contrasting languages C and ML.
6. The author states "The purpose of type-checking is to prevent the application of operations to incorrect types of operands." He infers that a language in which
this type checking guarantees that operations are only applied to the correct type of operands is strongly-typed. Give an example of such a
language as explain why that is the case. Select a language that includes type checking but for which this is not the case and give an example to support your selection.
7. There are two function definitions below. The first in C and the second in ML
int f(char a, char b) { //definition in C
return a==b;
}
fun f(a, b) = (a = b); (* definition in ML*)
One friend of mine says that the function in C demonstrates a greater degree of polymorphism because type checking is not that strong in C, and another says the
function definition in ML is more polymorphic. Side with one of these opinions, and write a supporting explanation.
8. One of these is an example of subtype polymorphism. Select it and then write an explanation supporting your selection.
a. The way the expression a+b is evaluated in C, when a is an int and b is a float.
b. The way the length function in ML works on any type of the form 'a list.
c. The way the + operator in C applies to pairs of integers and also to pairs of real numbers.
d. The way a function in Pascal can take a parameter of type Day (an enumeration of the days of the week) or of type Weekday (the same, but omitting Saturday and Sunday).
9. One of these is an example of parametric polymorphism. Select it and then write an explanation supporting your selection.
a. The way the expression a+b is evaluated in C, when a is an int and b is a float.
b. The way the length function in ML works on any type of the form 'a list.
c. The way the + operator in C applies to pairs of integers and also to pairs of real numbers.
d. The way a function in Pascal can take a parameter of type Day (an enumeration of the days of the week) or of type Weekday (the same, but omitting Saturday and Sunday).
10.[Exercise 3 p 131] Consider an unknown language with integer and real types in which 1 +2, 0 + 1, 1 +2.0, ad 1.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.
d. Explain how this could result from subtype polymorphism, with no overloading or coercion.
11. [Exercise 4 p 131] 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, explain how the expression "1" + 2*3 is evaluated and give its value.
12. a. Explain the evaluation of foldl (op ^) "*" ["1+2+3", "4 + 5", "a/b -c"]
b. Explain the evaluation of foldr (op ^) "*" ["1+2+3", "4 + 5", "a/b -c"]
13. Explain the following function
fun thin x L = foldr( fn(a,b) => if a < x then b else a::b) [] L;
b. Now explain the evaluation of gt10 [12,3,15,4,~12,16] below.
val gt10 = thin 10;
gt10 [12,3,15,4,~12,16]
Possible types of ML questions -explain how a function operates, write something simple, evaluate a function applied to an item.
What is the result of evaluating the expression 1+2*3=4 in ML? (Circle one.)
a. a value of type int
b. a value of type bool
c. a compile-time error
d. a runtime error
What is the result of evaluating the expression -1 * -2 in ML? (Circle one.)
a. a value of type int
b. a value of type real
c. a compile-time error
d. a runtime error
What is the result of evaluating the expression 1 div 0 in ML? (Circle one.)
a. a value of type int
b. a value of type real
c. a compile-time error
d. a runtime error
What is the result of evaluating the expression if true then 1 in ML? (Circle one.)
a. a value of type int
b. a value of type bool
c. a compile-time error
d. a runtime error
What is the result of evaluating the expression #2 (1,true) in ML? (Circle one.)
a. a value of type int
b. a value of type bool
c. a value of type int * bool
d. a compile-time error
What is the result of evaluating the expression real 123 in ML? (Circle one.)
a. a value of type int
b. a value of type real
c. a compile-time error
d. a runtime error
What is the result of evaluating the expression true orelse 1 div 0 = 0 in ML? (Circle one.)
a. a value of type bool
b. a value of type int
c. a compile-time error
d. a runtime error
Explain the function mergesort in chapter 7. Note how pattern matching and let are used in the definition. Trace the application of mergesort to [10,23,12,45,14,25]. You've learned, when you studied programming in C++ and/or Java, that merge sort is a O(n logn) sort, where n is the number of items in the list. Explain whether that is still the case when we consider this implementation in ML.
Explain the operation of insertionsort that we discussed in class.