I have the following functions in Haskell that should print sales of weeks. Each sale in a new line. But it does not work as I expect. The problem is I have a newline character '\ n'.
the code:
printWeeks :: Int->String
printWeeks 0 = printWeek 0
printWeeks x = printWeeks(x-1) ++ printWeek x
printWeek :: Int->String
printWeek x = show(x) ++ " " ++ stars (sales x) ++ "'\n'"
I tried many ways, but the new line symbol does not work as expected. Everything is printed on the same line as not what I want.
Help is needed?
thank
UPDATE
The following steps do not work due to compilation errors. Errors come from the second line of formatLines. Type allocation causes errors. Need help here.
formatLine :: (Name,Price)->IO()
formatLine (a,b) = putStrLn (a ++ dots ++ p)
where
x=(length a)
p=(formatPence b)
y=length p
z=lineLength-(x+y)
dots = printDots z
formatLines :: [(Name,Price)]->IO()
formatLines []= ""
formatLines (a:x) = formatLines x ++ formatLine a
source
share