Python代写|FIT5196-S2-2022 Assessment 3
本次作业案例是一个Haskell代写编程的assignment
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 (…)
OVERALL SCORE = … / …
or
K out of N tests failed
OVERALL SCORE = … / …
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)])
23
ghci> assoc 0 “bob” [(“ranjit”,85), (“william”,23), (“moose”,44)]
0