quiz3-fall10

Quiz3-fall10 - describe the error(fun x> if(x> 0 then x 1 1 Value/Error = d(6 pts Using fold and an anonymous function write a function

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

View Full Document Right Arrow Icon
CMSC330 Fall 2010 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. Answer essay questions concisely in 2-3 sentences. Longer answers are not needed. 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. (2 pts) Give the type of the following OCaml expression fun x y -> x (y+2) Type = b. (2 pts) Write an OCaml expression with the following type (bool -> int) -> int Code = c. (2 pts) Give the value of the following OCaml expression. If an error exists,
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: describe the error. (fun x -> if (x > 0) then x+1) 1 Value/Error = d. (6 pts) Using fold and an anonymous function, write a function attendance which when applied to a list lst of bools, returns the number of elements of lst that are true. Example: attendance [true; false; false; true; true] = 3 let rec fold f a l = match l with -> a | (h::t) -> fold f (f a h) t 2. (8 pts) Context free grammars a. (2 pts) Write a grammar for a x b y , where x = y+3 (i.e., exactly 3 more a’s than b’s) b. (6 pts) Consider the following grammar (where S = start symbol and terminals = [ , ] , ; , e ): S & [ A ] | epsilon A & A ; S | e i. (3 pts) Present a derivation for the string [e;[e;]] ii. (3 pts) Show the parse tree for your derivation...
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

Quiz3-fall10 - describe the error(fun x> if(x> 0 then x 1 1 Value/Error = d(6 pts Using fold and an anonymous function write a function

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online