![]() |
.. (לתיקייה המכילה) | |
In question 2b, do we have to check if the sequence contains only digits 2-9 and/or if it's infinite?
| No, you can assume that play() will receive only sequences created by the function startGame() or Nil. |
In question 2a, what happens if the list of digits is empty?
| Then all the elements will be Num(n) and there will be no booms. |
In question 3, may we assume that all elements in the sequence are unique?
| No, they don't have to be unique. |
My solution for question 3 runs in O(n^2) time, is this ok?
| You can reverse the sequence in O(n) time. Solutions that need O(n^2) time will not get full points. |
Some of my functions return values like "val it = Nil : ?.X1 seq" when receiving empty lists/sequences. Is this fine?
| Yes, it's ok. ML sometimes gets confused when you send polymorphic parameters to polymorphic functions. You don't have to do anything about it. |
In question 3, my function returns the last element and removes it from the sequence each time I call "tail it". Is this fine?
| This implies a complexity of O(n^2) to iterate over the returned sequence, and therefore this solution will not get full points. |
Q3 hint:
| look at how you implemented the nrev function in HW4. Your solution here should be similar. |
I don't understand the restrictions in Q4.
|
The restrictions simply state that each tail function can iterate over the entire sequence once. So in the example (sortSeq op< (toSeq [40,30,60,20,40])), you can only iterate over at most 5 elements each time you call the tail function. |
My solution for Q4 needs to iterate over the sequence twice: once to find the minimal element and once to remove it from the sequence. Is this fine?
|
No, this violates the restriction that you can only iterate over the sequence once. Hint: instead of removing the minimal element, you can change the tail function so that it will "know" not to return it again. Look at the "primes" example from the tutorial for clues how to do that. |
I can't put examples of exceptions in the examples file, since it stops running the examples.
|
Please show examples of exceptions by catching them (using handle) and returning some value of the needed type. For example, if a function f returns an int and throws an exception, then write "f(x) handle <whatever> => -1". Write a comment if it's not clear what you did. |

