[Haskell-cafe] IO and lazyness.
dav.vire+haskell at gmail.com
Tue Mar 6 16:56:52 EST 2007
> The problem is that hGetContents only reads the contents of the file on demand
> and, without the 'return $!' you don't demand the value until somewhere
> outside of rechf. By this point the hClose has happened and hGetContents has
> no access to the file => no lines => no result.
I must be really dumb but I don't get why 'at this point the hClose
It seemed to me that when I typed at ghci's prompt rechf "xxxx" it
tries to evaluate it.
that makes it perform the IO action of opening the file, then
performing the IO action of evaluating ( since I need the result )
rechf2 "xxxx" and *lastly* performing the IO action of closing the
So to me either I'm just too confused to understand or something
doesn't work as it should be.
I also tried using readFile ( again following Jeremy's suggestion )
and it works :
> rechf r = do
> f <- readFile "liste"
> return $ rech r $ lines f
More information about the Haskell-Cafe