[Haskell-cafe] Newbie question

David Roundy droundy at darcs.net
Fri Aug 12 08:49:25 EDT 2005

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
David Roundy

More information about the Haskell-Cafe mailing list