[Haskell] IO Regions in Haskell98

Simon Peyton-Jones simonpj at microsoft.com
Tue Jan 24 03:57:41 EST 2006


| however that there is a Haskell98 implementation of IO regions. The
| solution involves no higher-ranked types, and works both in GHC and
| Hugs. The idea is trivial: given
| 
| > newtype Q = Q Handle
| > newtype IOM a = IOM (IO a)
| > qGetChar :: Q -> IOM Char
| > withFile :: FilePath -> (Q -> IOM a) -> IOM a
| 
| we wish to assure that the handle Q never escapes, neither explicitly
| nor implicitly.

Don't side effects kill you?

	withFile "foo" (\q -> writeIORef var q)

So would unsafePerformIO

	withFile "foo" (\q -> return (unsafePerformIO (qGetChar q)))

Simon


More information about the Haskell mailing list