The Int
is the count of the number of instances of a
in the List
> frequencyMap [1, 2, 3, 1, 3, 1]
fromList [(1,3),(2,1),(3,2)]
> insertionSort "PAPAYA"
"AAAPPY"
> insert 'T' $ insertionSort "PAPAYA"
"AAAPPTY"
The Frequency
type, is defined by:
type Frequency = (Int, Char)
You should use the frequencyMap
and insertionSort
functions
You can also use the swap
function from Data.Tuple
Examples:
> frequencies "PAPAYA"
[(1,'Y'),(2,'P'),(3,'A')]
> frequencies "Zapallo con Papa"
[(1,'P'),(1,'Z'),(1,'c'),(1,'n'),(2,' '),(2,'l'),(2,'o'),(2,'p'),(4,'a')]
- Takes as an argument a file name (Use
getArgs
) - If the file name is not specified prints an error message
- Reads the file (Using
readFile
). - Counts the frequencies of the letters in the file
- Prints the table of frequencies in REVERSE order (Starting from the higher ones).
> freq example.txt | head
' ': 292
'e': 148
'o': 124
't': 98
'h': 96
'n': 95
'a': 93
's': 92
'r': 68
'i': 65