[Haskell-beginners] Question about IO, particularly hGetContents
Ken Overton
koverton at lab49.com
Thu Apr 1 21:06:19 EDT 2010
Hello all, I was playing with some Haskell code that read in text files and processed them and often found myself writing empty result-files. I've pared the problem down to the following small example.
-- example program
import IO
main = do
rhdl <- openFile "test.in" ReadMode
content <- hGetContents rhdl
putStrLn content -- if I cmt out this line, content will be empty
hClose rhdl
putStrLn "Content: "
putStrLn content -- if the first 'putStrLn' call was commented, this will print a blank line
-- end example
For some reason, if I comment out the 'putStrLn content' between hGetContents and hClose, the data from the hGetContents call is not stored. Can somebody verify this behavior and (if so) explain why it's happening?
Thanks,
-- kov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100401/ba4a5cc7/attachment.html
More information about the Beginners
mailing list