RealWorld

Ross Paterson ross at soi.city.ac.uk
Fri Sep 19 02:08:57 EDT 2003


On Thu, Sep 18, 2003 at 04:01:08PM -0700, Ashley Yakeley wrote:
> In article <20030918091948.GA29877 at soi.city.ac.uk>,
>  Ross Paterson <ross at soi.city.ac.uk> wrote:
> 
> > NHC doesn't have ST (rank-2 types).  In Hugs, they are now
> > 
> > 	newtype IO a = IO ((a -> IOResult) -> IOResult)
> > 	newtype ST s a = ST (forall r. (a -> r) -> r)
> 
> Oh now that's interesting. Presumably in Hugs IO and ST s could be made 
> instances of MonadCont very easily?

I view it a trick to force sequencing (like GHC's state transformer
representation of IO, and similarly inaccurate), not to be exposed in
the interface (including special instances).  (But it does make stToIO
and runST easy to implement.)

> How does Hugs do fixIO?

It's nothing deep:

	fixIO :: (a -> IO a) -> IO a
	fixIO f = do
		r <- newIORef (throw NonTermination)
		x <- f (unsafePerformIO (readIORef r))
		writeIORef r x
		return x

I'm not claiming this is valid for all continuation monads, or other
representations of IO.  I don't even think IO is really a continuation
monad (or a state transformer).


More information about the Libraries mailing list