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
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: ..." , ... ]
>
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
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
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 ::
| 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
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