|COMP1011 Exercises for Week 05|
|Computing 1A 05s2||
Tue 19 Jul 2005 14:37
Please make sure that you have carefully read the specification for Assignment 1. Make a list of all the points that you don't understand and ask your tutor about them.
Write a recursive function
delete which, given a string and
a character, returns the string with all occurances of the character
Tut05> delete 'x' "x-files sux" "-files su"
In a similar style as
delete, write a function substituting
a given character with another character (instead of deleting it):
Tut05> substitute 'e' 'i' "eigenvalue" "iiginvalui"
Write a function that returns both the shortest and the longest string in a list:
Tut05> shortestAndLongest ["abc"] ("abc","abc") Tut05> shortestAndLongest ["This", "sentence", "is", "ridiculous"] ("is","ridiculous")
What do you think should happen when an empty list is passed to
Write a function that yields a list of all the properties associated with all occurrences of a key in an association list:
Tut05> lookupAll "Plates" [("Forks", 10), ("Plates", 5), ("Cups", 0), ("Plates", 1)] [5,1] Tut05> lookupAll "Knives" [("Forks", 10), ("Plates", 5), ("Cups", 0), ("Plates", 1)] 
It is sufficient if the function works only for association lists of
Is their anything that prevents
delete to be used on lists
of integers? What type do you have to give
delete, so that
a single implementation works on lists of characters (ie, strings) and
list of numbers?
Discuss the type signatures of
trace :: String -> a -> a show :: Show a => a -> String
Discuss the style requirements for Assignment 1.