Nick Name wrote:

> I would like to use hGetContents just to retrieve the list of the lines
> of a file, but if I code a function like:
> 
> linesFromFile :: FilePath -> IO [String]
> linesFromFile f = do
>       h <- openFile f ReadMode
>       l <- hGetContents h
>       hClose h
>       return (lines l)
> 
> I obviously always get the empty list as a result. How should I code the
> function?

Just omit the hClose; hGetContents will automatically close the handle
once all of the data has actually been read. See §11.2.1 of the
library report for details.

-- 
Glynn Clements <[EMAIL PROTECTED]>
_______________________________________________
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to