quiz2-spr10 - function getFirsts which given a list of...

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

View Full Document Right Arrow Icon
CMSC330 Spring 2010 Quiz #2 Name Discussion Time (circle one): 9am 10am 11am 12pm 1pm 2pm Instructions You have 20 minutes for this quiz. This is a closed book exam. No notes or other aids are allowed. For partial credit, show all of your work and clearly indicate your answers. Write neatly. Credit cannot be given for illegible answers. 1. (6 pts) OCaml Types and Type Inference a. (2 pts) Give the type of the following OCaml expression fun x -> (x,2) Type = b. (2 pts) Write an OCaml expression with the following type int -> (float * int list) Code = c. (2 pts) Give the value of the following OCaml expression. If an error exists, describe the error. (fun z -> fun y -> z - y) 5 3 Value =
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. (8 pts) OCaml Programming Using the following code for either map/fold and an anonymous function, write a
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: function getFirsts which given a list of pairs, returns a list of the 1 st members of each pair as a list (in original or reverse order). Partial credit given for solutions which do not use map/fold. Example: getFirsts [(1,2);(3,4);(3,5)] = [1;3;3] OR [3;3;1] getFirsts [(“a”,”x”);(“b”,”y”);(“c”,”z”)] = [“a”;”b”;”c”] OR [“c”;”b”;”a”] 3. (6 pts) Context free grammars Consider the following grammar: S & aSaS | ± (* epsilon *) a. (2 pts) Describe the set of strings generated by the grammar. b. (4 pts) Is the grammar ambiguous? Show proof if possible. let rec map f l = match l with -> | (h::t) -> (f h)::(map f t) let rec fold f a l = match l with -> a | (h::t) -> fold f (f a h) t...
View Full 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