fixIO

Ross Paterson <[email protected]> Tue, 2 Sep 2003 14:46:39 +0100
Newsgroups gmane.comp.lang.haskell.nhc.bugs
Message-ID <[email protected]>
The definition of fixIO used by Nhc (in System.IO), namely

	fixIO f = let x = unsafePerformIO (f x) in return x

produces the wrong results for programs like

	main = do
		putStrLn "aaa"
		ds <- fixIO $ \ds -> do
			putStrLn "bbb"
			return ('d':ds)
		putStrLn "ccc"
		putStrLn (take 3 ds)

(The "left tightening" law says that moving putStrLn "bbb" up a line
should not change the meaning.)

I suggest:

	fixIO f = IO (\w -> let { IO f' = f a; r = f' w; Right a = r } in r)