I was counting on this to be an easy one. There was too much going on around it (compare the last two articles, and the ones on this Thursday and Friday) to dedicate much time to it.
But why, oh why didn't I memorise the exact definition of foldr?
Overall, this wasn't the shocker that was IM2, but it had enough to rile me on the bus home.
The marking inequalities arose again here: 15 marks for two function definitions and a proof by structural induction (on a Binary Tree <gasp>); versus 15 marks for the definition of foldr. (With foldr, I forgot that the type was (a -> b -> b) -> b -> [a] -> [b], instead believing that it was all a's. However, I can't complain about this - I messed up the generous question, but c'est la vie.
You'll maybe be wondering what my bugbear is. The very last question, of course!
6. Define a Haskell algebraic type to represent course modules. Each module has the following attributes: the module name, the number of students taking the module, and a list of matric numbers of the students who have passed the module.
(c) Define a function passrate which, for given modules x and y, returns the proportion of students who have passed either module x or module y.
Besides the fact that we haven't worked with Floats/Doubles/Rationals, so proportion calculation was a bit of a surprise, consider what the question is asking.
The function is given two modules, each with a possibly-different number of students taking it. Say, for example, that m people take module x, and n take module y. How many people take both exams? We know that it is at least min{m,n}, and at most (m+n), but not the exact number; nor is it calculable from the information that we are given about the modules.
We can calculate the number of students who passed either exam, certainly (it was in the previous part of the question); but to find the proportion, by what number should we divide? I propose that this question was insoluble.
Ah well, nothing like an FP2 exam to put the colour back in your cheeks....
Cheers,
Derek.
|