CMSC330 Spring 2011 Quiz #3 Name Discussion Time (circle one): 9am 10am 11am 12pm 1pm 2pm Instructions • Do not start this test until you are told to do so! • You have 15 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. (12 pts) OCaml a. (4 pts) Give the type of the following OCaml expressions, or write “ERROR” if there is none. Here map refers to the standard curried list-processing function that was covered in class (and is also implemented in the List module). fun x y -> x (y+1) Type = map (fun x -> 2*x) Type = b. (2 pts) Write an OCaml expression (not a declaration!) with the following type (bool -> int) -> int Code = c. (6 pts) Write a function rmZeros that, given a list of integers, returns the same list except with all occurrences of 0 removed. For example, rmZeros [1;0;2;0] should return [1;2].2. (4 pts) Scope rules Consider the following OCaml declarations. let x = 0;; let f y = x;; The following questions refer to the expression let x = 1 in f x a. (2 pts) Under OCaml’s usual static scoping rules, what is the value of the expression? b. (2 pts) Now suppose OCaml uses dynamic scoping instead. What would the value of the expression
View Full Document