I want a program that takes lines and prints reverse when it encounters an empty line. This is my code.
back :: IO()
back = do
line <- getLine
if (not $ null line) then do
mapM_ putStrLn (reverse line)
else return()
When I try to run this it gives an error.
* Couldn't match type `Char' with `[Char]'
Expected: [String]
Actual: [Char]
* In the second argument of `mapM_', namely `(reverse line)'
In a stmt of a 'do' block: mapM_ putStrLn (reverse line)
In the expression: do mapM_ putStrLn (reverse line)
|
6 | mapM_ putStrLn(reverse line)
| ^^^^^^^^^^^^
What is going wrong here?