How can I implement in haskell the following:
- I receive an input file from the command line. This input file contains words separated with tabs, new-lines and spaces.
- I have to replace these elements (tabs, new-lines and spaces) with commas.
- And then write the result to a file called
output.txt
.
Any help is much appreciated. My haskell skills still developing.
So far I've got this code:
processFile::String->String
processFile [] =[]
processFile input =input
process :: String -> IO String
process fileName = do
text <- readFile fileName
return (processFile text)
main :: IO ()
main = do
n <- process "input.txt"
print n
In processFile function I should process the text from the input file.
You can use the
getArgs
function to read arguments on the command line. For example:You can use the
readFile
function to read a file.You can use the
writeFile
function to write a file:Tabs, newlines and spaces can be called whitespace, or word separators. The
words
function converts a string into a list of words.The
intersperse
function inserts a separator between each element of a list:You can also look at the
intercalate
function if you need longer separators.These are all of the tools that you need for your program, I think that you can figure out the rest. Good luck!