
12 Aug
2005
12 Aug
'05
12:49 p.m.
On Fri, Aug 12, 2005 at 09:17:32AM -0300, Andr Vargas Abs da Cruz wrote:
readDataFromFile filename = do bracket (openFile filename ReadMode) hClose (\h -> do contents <- hGetContents h return (lines contents))
The question is: if i try to run this, it returns me nothing (just an empty list). Why does this happen ? When i remove the "return" and put a "print" instead, it prints everything as i expected.
I think that this may be because hGetContents puts the file in a semi-closed state (and reads the contents lazily). Try removing the hClose (replacing it with (return ()). Lazy IO is nice, but gets tricky at times. -- David Roundy http://www.darcs.net