This preview has intentionally blurred parts. Sign up to view the full document

View Full Document

Unformatted Document Excerpt

1 Spring, 2013 Name: (Please do not write your id number!) COP 4020 Programming Languages I Test on Haskell and Functional Programming Special Directions for this Test This test has 7 questions and pages numbered 1 through 8. This test is open book and notes, but no electronics. If you need more space, use the back of a page. Note when you do that on the front. Before you begin, please take a moment to look over the entire test so that you can budget your time. Clarity is important; if your programs are sloppy and hard to read, you may lose some points. Correct syntax also makes a difference for programming questions. Take special care with indentation and capitalization in Haskell. When you write Haskell code on this test, you may use anything we have mentioned in class that is built-in to Haskell. But unless specifically directed, you should not use imperative features (such as the IO type). You are encouraged to define functions not specifically asked for if they are useful to your programming; however, if they are not in the standard Haskell Prelude, then you must write them into your test. (That is, your code may not import modules other than the Prelude.) Hints If you use functions like filter , map , and foldr whenever possible, then you will have to write less code on the test, which will mean fewer chances for making mistakes and will leave you more time to be careful. The problem will note explicitly if you are prohibited from using such functions, but by default you can. In the follow the grammar problems the examples may be very extensive and take a long time to read if you read every detail. But the basic idea of the recursion is usually clear from the description, simple examples, and the follow the grammar idea of recursing everywhere possible. So look to the examples to confirm your understanding and dont spend too much time reading examples after you understand the problem. For Grading Question: 1 2 3 4 5 6 7 Total Points: 10 5 10 15 15 20 25 100 Score: 2 1. (10 points) [UseModels] In Haskell, write the function: squareEvens :: [ Integer ] -> [ Integer ] that takes a list of Integers, lst , and returns a list of Integers that is just like lst , except that each even element of lst is replaced by the square of that element. In your solution, you might find it helpful to use the built-in predicate even . The following are examples, written using the Testing module from the homework. tests :: [TestCase [ Integer ]] tests = [eqTest (squareEvens []) "==" [] ,eqTest (squareEvens [3]) "==" [3] ,eqTest (squareEvens [4]) "==" [16] ,eqTest (squareEvens [4,3]) "==" [16,3] ,eqTest (squareEvens [1,2,3,4,5,6]) "==" [1,4,3,16,5,36] ,eqTest (squareEvens [3,22,3,95,600,0,-2]) "==" [3,484,3,95,360000,0,4] 3 2. (5 points) [Concepts] [UseModels] Consider the data type2.... View Full Document

End of Preview

Sign up now to access the rest of the document