quiz2-spr10

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

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

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 =

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

View Full Document
2. (8 pts) OCaml Programming Using the following code for either map/fold and an anonymous function, write a
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

## This note was uploaded on 01/13/2012 for the course CMSC 330 taught by Professor Staff during the Fall '08 term at Maryland.

### Page1 / 2

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online