Thanks for a very clear bug report - I'll bet it was no fun trying
 to isolate this problem!

Koen Claessen ([EMAIL PROTECTED]) writes:
> -- begin code
> 
> module Bug where
> 
> import IOExts
> 
> main :: IO ()
> main = writeFile "cat" buggy
> 
> buggy :: String
> buggy = unsafePerformIO $
>   do writeFile "cow" "Animal Farm"
>      return "horse"
> 
> -- end code
> 
> After running `main', you get an "unexpected signal", and Hugs crashes.
> 
> The combination of the following two things causes the problem:
> 
>   - the writing to a file of an unsafe string,
>   - that when evaluated writes to another file.
> 
> Either one of these things is no problem; [...]

The problem is the implementation of writeFile which uses a global
variable to keep track of which file it is writing to.  This is
perfectly ok if you're not using unsafePerformIO but obviously
fatal otherwise.

Rewriting the writeFile function as follows avoids this problem:

writeFile :: String -> String -> IO ()
writeFile fn s = do
  f <- openFile fn WriteMode 
  hPutStr f s
  hClose f

File reading doesn't seem to suffer from this problem.

I'm afraid I don't plan to fix this right away - it'd require
quite a bit of code rearranging and I'm deep in the bowels of
the code generator/ evaluator at the moment.  It shouldn't be
a problem in the new system (see Hugs news page).


-- 
Alastair Reid              Yale Haskell Project Hacker
[EMAIL PROTECTED]  http://WWW.CS.Yale.EDU/homes/reid-alastair/


Reply via email to