That seems odd to me.  Shouldn't hclose be a no-op on a
semi-closed handle?  Otherwise the behaviour of the program
is (a) unexpected and (b) depends on evaluation order.

Simon

> As far as I can see, the problem is your call to hClose.
> Delete it and read about semiclosed handles in the Haskell library report.
> 
> Alastair
> 
> > Version:       hugs 1.4 
> > OS:            Win 95 & Win NT 4.0 
> > 
> > I wrote this program in file named "foo.hs"
> > 
> > >import IO
> > >main = do hfoo <- openFile "foo.hs" ReadMode
> > >          xs <- hGetContents hfoo
> > >          hClose  hfoo
> > >          putStr xs
> > 
> > I wanted it prints itself, but it shows "".
> > 
> > So, I changed it by adding the following line of code ...
> > 
> > >import IO
> > >main = do hfoo <- openFile "foo.hs" ReadMode
> > >          putStr xs
> > >          xs <- hGetContents hfoo
> > >          hClose  hfoo
> > >          putStr xs
> > 
> > and the result was print twice copy of the program.
> > 
> > Moreover, I tried to re-implement the function hGetContents using hGetLine
> > and the Hugs' version of hIsEof (hugsHisEOF) but I had problem with the
> > last one.
> > 
> > I think it isn't working well. 
> > I have solved my problem using the catch function and IOError, but is there
> > an easy solution for this problem?

Reply via email to