DOC PREVIEW
UMD CMSC 330 - Quiz 2 Answers

This preview shows page 1 out of 3 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CMSC330 Summer 2009 Quiz 2 Name: _________Answers________________________________ 1. Functional languages (4 points) a. Why is Ocaml considered a functional programming language? Focuses on expression evaluation with less emphasis on memory writes; has higher-order functions; heavy use of recursion, etc. b. Give one reason why someone might want to use a functional language over an imperative one. Your answer should not be along the lines “…because they are better at/like functional languages more…” Easier to parallelize code when there aren’t memory writes 2. What is a higher order function? That is, what can you do with higher order functions that you cannot do with “regular” functions? (2 points) First class variable; can be passed to or returned from a function3. Give the types (as Ocaml would) of the following expressions, or ERROR if there is an error: (7 points) a. [2;‘c’] _______________error – heterogenous types_________ b. (2,‘c’) _______________int * char_______________________ c. [1;2;3] _______________int list__________________________ d. (‘c’;“hello”)_______________error – tuple uses , not ; ____________ e. [[1;2;2];[2;3]]_____________int list list________________________ f. [[[1;2]];[2;3]]_____________error – not same level of nesting______ g. Printf.printf “%d” 3 __________unit__________________________ 4. Give the type of the following functions or ERROR if there is an error (4 points): a. let head l a = match l with [] -> (1,(1+a)) | _ -> (0,1) ;; ___’a -> int -> int * int________________________________________ b. let head l = match l with [] -> [] | _ -> (0,1) ;; ___error – does not return same type______________________ 5. Give the value of the following Ocaml expressions or ERROR if there is an error (5 points) a. let x = 3 in x::[] _____________[3]________________________ b. let x = 3 in x@[1;2;3] ___error – concat list operator expects 2 lists___c. List.map((fun z -> z + z),[1;2;3]) ____[2 ;4 ;6]_______________________________ d. let x = 2 in let y = 3 in x::y::[2;4;6]______[2;3;2;4;6]_____________________________ e. let list = [1;2;3] in match list with [] -> -1 | (h::t) -> if (h <> 3) then 0 else 1


View Full Document

UMD CMSC 330 - Quiz 2 Answers

Documents in this Course
Exam #1

Exam #1

6 pages

Quiz #1

Quiz #1

2 pages

Midterm 2

Midterm 2

12 pages

Exam #2

Exam #2

7 pages

Ocaml

Ocaml

7 pages

Parsing

Parsing

38 pages

Threads

Threads

12 pages

Ruby

Ruby

7 pages

Quiz #3

Quiz #3

2 pages

Threads

Threads

7 pages

Quiz #4

Quiz #4

2 pages

Exam #2

Exam #2

6 pages

Exam #1

Exam #1

6 pages

Threads

Threads

34 pages

Quiz #4

Quiz #4

2 pages

Threads

Threads

26 pages

Exam #2

Exam #2

9 pages

Exam #2

Exam #2

6 pages

Load more
Download Quiz 2 Answers
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Quiz 2 Answers and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Quiz 2 Answers 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?