[Haskell-cafe] Newbie question
Lemmih
lemmih at gmail.com
Fri Aug 12 08:54:03 EDT 2005
On 8/12/05, David Roundy <droundy at darcs.net> wrote:
> 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.
Or better yet, use 'readFile'.
--
Friendly,
Lemmih
More information about the Haskell-Cafe
mailing list