CSC 8310 -- Haskell 98 Assignment
Section 001: Tuesday & Thursday 4:30 to 5:45pm in Mendel G30
Section 002: Thursday 6:15 to 8:45 in Mendel G30
Spring 2000, Villanova University
Write and test the following two functions:
countLetters that, given a string as an argument,
counts the number of each letter in the string and returns the result as a list of 26
integers. Capital letters and lowercase letters should be counted as the same. Characters
that are not letters should be ignored.Examples:
countLetters "Amazingly few discotheques provide jukeboxes."
[2,1,1,2,6,1,1,1,3,1,1,1,1,1,3,1,1,1,3,1,2,1,1,1,1,1]
countLetters "ABRAcadabra"
[5,2,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0]
Suggested approach: Don't start out by trying to do the whole thing at once! Play around with some of the higher-order functions, and try things out at the Haskell prompt. Start with smaller pieces (can you count how many times a particular letter occurs?). Turning it into a function and testing the function should be your last step.
tr that takes three strings as arguments.
Assume that the first and second strings are the same length (that is, don't do any error
checking). In the third string, replace each occurrance of a character in the first string
with the corresponding character in the second string. Examples:
tr "aeiou" "AEIOU" "Amazingly few discotheques provide jukeboxes."
AmAzIngly fEw dIscOthEqUEs prOvIdE jUkEbOxEs.
tr "aeiou" "_____"
"Amazingly few discotheques provide jukeboxes."
Am_z_ngly f_w d_sc_th_q__s pr_v_d_ j_k_b_x_s.>
tr " ." "-!" "Amazingly few discotheques provide jukeboxes."
Amazingly-few-discotheques-provide-jukeboxes!
Note: Once you have a basic understanding of Haskell, these are not difficult functions. The first can be done in a single line; the second one took me six lines total (four of them in an auxiliary function). Your programs do not have to be this short, but if you find your program getting significantly longer than this, you may want to stop and reconsider your approach.
Turn in: Paper listings of your program and a transcript. No floppies, please!
Due: Thursday, April 27.