Exam2F06Hints - Design of Programming Languages Fall 2006...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Design of Programming Languages - Fall 2006 Second Exam : Nov. 14, 2006 Student Name: 1. , 2. , 3. , 4. , 5. , 6. , 7. Do any 5. 1. (10 pts) ML and Types. Derive the types, or point out the type errors, of (a) (3 pts) fun F1 g = g (F1 g) (b) (3 pts) fun F2 g x = g (F2 g) x (c) (2 pts) val g = fn f => fn x => if x = 0 then 1 else f(x + 1) (d) (2 pts) val g = fn f : real => fn x => if x = 0 then 1 else f(x + 1); Hint: RUN them and then try to reconstruct why... 1
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2. (10 pts) Fixed Points and Evaluation Strategies . (a) (5 pts) Using the Tarski (i.e., approximation) construction, find the least fixed point for the function g = λf.λn. if n = 0 then 1 else f ( n + 1) . Soln.: g 0 = , g 0 = { ( n, ) | ∀ n 0 } . g 1 = g ( g 0 ) = λn. if n = 0 then 1 else ( n + 1), g 1 = { (0 , 1) } ∪ { ( n, ) | ∀ n > 0 } . g 2 = g ( g 1 ) = λn. if n = 0 then 1 else g 1 ( n + 1), g 2 = { (0 , 1) } ∪ { ( n, ) | ∀ n > 0 } . . . . g k = g ( g k 1 ) = λn. if n = 0 then 1 else g k 1 ( n + 1), g k = { (0 , 1) } ∪ { ( n, ) | ∀ n > 0 } . . . . Since g 1 = g k k 1, we must have the limit g = { (0 , 1) } ∪ { ( n, ) | ∀ n > 0 } , (b) Taking the ML functions F1 and F2 of the previous problem, explain what should be returned, and why, by the calls F1 g 0 F1 g 1 F2 g 0 F2 g 1 Hint (for where it may be relevant): recall that ML implements proper tail-recursion. Soln.: RUN them in mosml or SML/NJ and explain the behavior by thinking about the way ML evaluates parameters. Lecture6, slides 48 and following should be helpful. 2
Image of page 2
3. (10 pts) Type Judgments and ML code . Consider the two judgments for Array Formation and Array Get. τ is a type ARRAY( τ ) is a type Γ ξ , Γ φ , Γ ρ e 1 : ARRAY( τ ) Γ ξ , Γ φ , Γ ρ e 2 : INT Γ ξ , Γ φ , Γ ρ ARRAY-GET( e 1 , e 2 ) : τ Within the function fun typeof (e, globals, functions, formals) of typed Impcore, you have the function ty , which takes only the expression e as an argument, using the remaining arguments of typeof as free variables and returns the type of its argument according to the type judgment above. Write the code completing ty(AGET(a, i)) where AGET(a, i) is the appropriate form of the expression e . Soln.: check your homework. One of the more common errors had to do with the ex- pectation that the type of the elements of the array had to be of INTTY, BOOLTY or UNITTY... there is NO reason why it could not be an array... There was also occasional confusion between type-checking and evaluation : the two phases are separate and don’t interact.
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern