{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw2 - Suggested Homework#2 Suggested Homework#2(for Quiz#2...

This preview shows pages 1–3. Sign up to view the full content.

Suggested Homework #2 Suggested Homework #2 (for Quiz #2 on 10/5/06) Problem 1: Suppose that the following list of bindings was entered into the OCaml interpreter in the sequence shown. For each binding, write down : (a) If the expression is accepted, the value bound ("fn" for functions) and its type, (b) If the expression is rejected due to a type error, "type error", (c) If the expression is rejected due to an unbound variable, the name of the variable that is not bound. Recall that if a type error occurs, then the variable binding does not happen. Check your answers by entering this sequence into the interpreter. - let a = let x = 20 in let y = let x = 5 in x + x in x + y ;; - let b = let x = "ab" in let y = (let x = "cd" in x) ^ x in x ^ y ;; - let c = let x = 22 in x::y ;; - let rec f x = if x > 0 then x :: (f (x-2)) else 0;; - let g x = x * a;; - let a = -1 ;; - let f x = let a = 20 in a + (g x) ;; http://www.cs.ucsd.edu/classes/fa06/cse130/shw/shw2.html (1 of 3) [2/13/2008 5:22:12 PM]

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

View Full Document
Suggested Homework #2 - let z = (f 5) * a ;; Problem 2: In each part below you are required to complete the
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern