[Haskell] IO == ST RealWorld

John Meacham john at repetae.net
Sun Jan 29 07:32:05 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.


ST doesn't have exceptions which IO does. It would be no good to make ST
pay for the cost of exception handling. GHC handles them behind the
scenes (I think?) but in jhc they are explicit and IO is defined as
follows:

> data World__
>
> data IOResult a = FailIO World__ IOError | JustIO World__ a
> newtype IO a = IO (World__ -> IOResult a)

I belive other implementations have used continuations for IO as well.

        John


--
John Meacham - ⑆repetae.net⑆john⑈


More information about the Haskell mailing list