[Haskell-cafe] A GHC error message puzzle

The file "error_puzzle.hs" begins like this: main = do inp <- readFile "input" writeFile "output" $ process inp process :: String -> String When compiled with GHC 6.12.3 and run, it gives the following result: $ ./error_puzzle error_puzzle: output: hClose: illegal operation (handle is finalized) What is the cause of the error? Give a definition for process and an input file that reproduce this result. No "unsafe" functions like unsafePerformIO are allowed. Have fun! -Yitz