Unless stated otherwise, do not use library functions that are not in the Haskell standard prelude.
7. There are two parts to this question; do part (b) first.
a. [1 mark] Write the function barchart :: Int -> [(String, Int)] -> String that takes a width specifier, say w, and a list of (label, value) pairs, and draws a horizontal bar chart.
For example, barchart 5 [("xxxx", 5), ("yyy", 8), ("zzzzzzzz", 3)] = "xxxx *****\nyyy ********\nzzzzz ***"
or using putStr for nicer display: putStr $ barchart 5 [("xxxx", 5), ("yyy", 8), ("zzzzzzzz", 3)] = "xxxx *****\nyyy ********\nzzzzz ***"
b. [1 mark] To implement barchart, first write the simpler function:
chart. One character is drawn for each value, and the label is shown padded out to w characters wide or truncated to w characters wide. Then barchart can be written in terms of bar, map, and unlines. Note that unlines :: [String] -> String is a standard prelude function that takes a list of strings and joins them together (similar to concat) after adding a newline character to the end of each string. The result is a single string that displays as a sequence of lines.