Re: A problem about hGetContents -- with another question

2003-01-23 Thread Dean Herington
I was unhappy with the use of `error` in my first solution, so I wrote a second solution that's more robust. It also demonstrates monadic style. The new solution is at the bottom. Dean On Thu, 23 Jan 2003, Dean Herington wrote: > On Sun, 19 Jan 2003, Nick Name wrote: > > > I got another tro

Re: A problem about hGetContents -- with another question

2003-01-22 Thread Dean Herington
On Sun, 19 Jan 2003, Nick Name wrote: > I got another trouble: I need to build a record type like > > Package { name :: String, version :: Int , mantainer :: String ... other > fields ... } > > from a list of string of the form > > ["Package: ..." , "Mantainer: ..." , "Version: ..." , ... ] >

Re: A problem about hGetContents

2003-01-19 Thread Nick Name
On Sun, 19 Jan 2003 17:19:52 + Glynn Clements <[EMAIL PROTECTED]> wrote: > > > 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. Thanks for this pointer. Quoting from the

Re: A problem about hGetContents

2003-01-19 Thread Glynn Clements
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

Re: A problem about hGetContents -- with another question

2003-01-19 Thread Nick Name
On Sun, 19 Jan 2003 08:51:31 -0800 "Mark P Jones" <[EMAIL PROTECTED]> wrote: > >linesFromFile = fmap lines . readFile Nice :) BTW, is readFile implemented with some strict evaluation construct ? I got another trouble: I need to build a record type like Package { name :: String, version ::

RE: A problem about hGetContents

2003-01-19 Thread Mark P Jones
| 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 o

A problem about hGetContents

2003-01-19 Thread Nick Name
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 alway