Download presentation
Presentation is loading. Please wait.
Published byMeghan Ward Modified over 9 years ago
1
CS383 Programming Languages Quiz 6
2
1. Which one is a term schema? a.‘a b.s :: = ‘a| int | bool c.fun f (x: int) : bool = e d.fun f (x: s1) : s2 = e
3
2. Which one is not a step of type inference? a.Add type schemas b.Generate type constraints c.Determine subtypes d.Solve type constraints
4
3. In the step of constraint generation, which simple rule is not totally correct? a.G |-- x ==> x : s, {} b.G |-- 2 ==> 2 : int, {} c.G |-- false ==> false : bool, {} d.G |-- true ==> true : bool, {}
5
4. In the step of constraint generation, which rule is not correct? G |-- u1 ==> e1 : t1, q1 G |-- u2 ==> e2 : t2, q2 ------------------------------------------------------------------------ G |-- u1 + u2 ==> e1 + e2 : int, q1 U q2 U {t1 = int, t2 = int} G |-- u1 ==> e1 : t1, q1 G |-- u2 ==> e2 : t2, q2 ------------------------------------------------------------------------ G |-- u1 e1 < e2 : bool, q1 U q2 U {t1 = int, t2 = int} G |-- u1 ==> e1 : t1, q1 G |-- u2 ==> e2 : t2, q2 ---------------------------------------------------------------- G |-- u1 u2==> e2 e1: a, q1 U q2 U {t1 = t2 -> a} G, f : a -> b, x : a |-- u ==> e : t, q ---------------------------------------------------------------- G|-- fun f(x)=u ==> fun f(x:a):b=e : a -> b, q U {t = b} a. b. c. d.
6
a.a solution to a system of type constraints is called a substitution b.substitution is a function from type variables to type schemes c.composition (U o S) applies the substitution U and then applies the substitution S d.any substitution is less general than the identity substitution I 5. Which statement is incorrect?
7
6. if S(a) = int, S(b) = c c ; T(a) = int, T(b) = c c, T(c) = int ; then we can conclude: a. T = S b. T >= S c. T <=S d. T is unrelated to S
8
7. Which of the following principal solution is incorrect? a.q = {a=int, b=a, b=bool} S : does not exist b.q = {x=int->x} S: does not exist c.q = {} S: does not exist d.q = {a=bool, b=a} S(a) = S(b) = bool, S(c) = c
9
8.Which one of the following constraint equation is impossible of a stuck state? a. int = bool b.‘a ’b = int c.a = s (s contains a) d. They are all possible
10
9. Which of the following rules is incorrect? a. ---------------------------------------------- (S, {s11 -> s12= s21 -> s22} U q) -> (S, {s11 = s21, s12 = s22} U q) b. ----------------------------------------(a not in FV(s)) (S,{a=s} U q) -> ([a=s] o S, q[s/a]) c. ----------------------------------------(a not in FV(s)) (S,{s=a} U q) -> ([a=s] o S, q[s/a]) d. They are all correct
11
10. Which of the following statement is incorrect? a. A complete solution for (S, q) is a substitution T such that T <= S and T |= q b. Every final state (S, { }) has a complete solution. c. No stuck state has a complete solution (or any solution at all) d. If (S, q) -> (S’, q’) then T is complete for (S,q) iff T is principal for (S’,q’)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.