| CS 330 | Home | Schedule | Resources |
Estimated time: 3 hours
[For these exercises, you may find it useful to examine the code snippets
in HaskellTest.hs here,
as well as glancing at this web tutorial
on Haskell. I wouldn't spend more than 30 minutes, tops, on the tutorial,
though. -Max]
Write a function pows(N X) in Haskell which returns a list of the first N powers of X, starting at 1. So the call pows(10 3) evaluates to [1,3,9,27,81,243,729,2187,6561,19683]. Note: in Haskell, the "!!" operator is equivalent to List.nth in Mozart: xs!!n gives the nth element of the list xs.
Show your code and answer the following questions:A.i. First execute "let x = (pows 100000000 3)". What is the type of x? What is the type of x!!1000? In terms of big-O, how much time does this operation take, given that it is lazy?
A.ii. Approximately how big is x in a logical sense, e.g. the total number of digits in all its members, independent of how it is implemented or created? How much memory do you suppose it actually occupies on your computer before any elements are accessed or used? Comment on the disparity or lack thereof.
B. Assume you have a function foo to create an infinite list of lists, where each inner list in the nth position has n elements. For example, the first five elements of this list might be
[[1], [2,2], [3,3,3], [4,4,4,4], [5,5,5,5,5]].i. How much time (in terms of big-O) does it take to execute let y=foo? ii. Then how much time does it take to execute y!!n? How would the answers to these two questions be different if foo eagerly created a finite list of length n?
let curry1 = (* 2)
let curry2 = (\x -> 2*x)
let a = curry1 7
let b = curry2 7
let c = (* 2) 7
let d = (2 * 7)
let exec = map curry1 Write a second server that cumulatively adds up all the results of the client requests, and outputs the tuple clientID#op#result#sum on a stream. (Hint: use the Port Object abstractions defined in 5.2.1 of the textbook.)