A problem about hGetContents

Mark P Jones mpj@cse.ogi.edu
Sun, 19 Jan 2003 08:51:31 -0800


| 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?

Try the following:

  linesFromFile :: FilePath -> IO [String]
  linesFromFile  = fmap lines . readFile

All the best,
Mark