[Haskell] IO == ST RealWorld

Ross Paterson ross at soi.city.ac.uk
Tue Jan 24 04:40:00 EST 2006


On Mon, Jan 23, 2006 at 09:55:39PM +0100, Twan van Laarhoven wrote:
> Is there any reason why IO should not be defined as:
>  > type IO a = ST RealWorld a
> in implementations that support ST?
> 
> This way IORef/STRef and IOArray/STArray can be merged. I know under the 
> hood they already share code, but this way they can also share an interface.

But IO isn't a state monad: others are concurrently changing the world
without waiting for my Haskell program to terminate.  Some compilers
use a state monad to enforce sequencing, but a continuation monad or
resumption monad would work just as well.

However IO does include a state monad, so one could define (using
IORegion instead of the presumptuous RealWorld):

	type IORef = STRef IORegion
	type IOArray = STArray IORegion
	type IOUArray = STUArray IORegion

	newIORef = stToIO . newSTRef
	...



More information about the Haskell mailing list