[Haskell-beginners] Reading, Processing, and Writing I/O

Dananji Liyanage dan9131 at gmail.com
Tue May 12 03:47:16 UTC 2015


Hi All,

As a newcomer to Haskell, I'm following a tutorial to learn I/O in Haskell.

As an exercise I'm writing a small code to read from an input text file and
process it and then write it back to an output file.

The problem is that, it doesn't write to the output file after the input is
being processed.

Here's my code:

    module Main where

    import System.IO

    main = do
     input <- readFile "input.txt"
     let reversedInput = reverseInput (convert input)
     writeFile "reversed.txt" (reversedInput)

     -- These two lines are not printed on the shell
     putStrLn (show reversedInput)
     putStrLn "Writing to file...."

    -- Reversing the input
    reverseInput input = (last input) : reverseInput (init input)
    -- Convert from String IO -> String
    convert x = show (x)


-- 
Regards,
Dananji Liyanage
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150512/b1c3792a/attachment.html>


More information about the Beginners mailing list