Haskell代写|cse130 Assignment 2: Random Art


Assignment Testing and Evaluation

All the points, will be awarded automatically, by evaluating your functions against a given
test suite.

Tests.hs contains a very small suite of tests which should give you a flavor of the sorts of
tests your assignment will be graded against. When you run

$ make test

Your last lines should have

All N tests passed (…)


K out of N tests failed

If your output does not have one of the above your code will receive a zero

If, for some problem, you cannot get the code to compile, leave it as in the starter code
(with error … ), with your partial solution enclosed below as a comment.

The other lines will give you a readout for each test. You are encouraged to try to
understand the testing code, but you will not be graded on this.

Problem #1: Tail Recursion

We say that a function is tail recursive if every recursive call is a tail call whose value is
immediately returned by the function.

(a) 15 points

Without using any built-in functions, write a tail-recursive function

assoc :: Int -> String -> [(String, Int)] -> Int

such that

assoc def key [(k1,v1), (k2,v2), (k3,v3);…])

searches the list for the first i such that ki = key . If such a ki is found, then vi is returned.

Once you have implemented the function, you should get the following behavior:

ghci> assoc 0 “william” [(“ranjit”, 85), (“william”,23), (“moose”,44)])
ghci> assoc 0 “bob” [(“ranjit”,85), (“william”,23), (“moose”,44)]


本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail: itcsdx@outlook.com  微信:itcsdx