difference between (evaluate . runST) and stToIO

Simon Marlow simonmar@microsoft.com
Tue, 13 Aug 2002 11:31:57 +0100


> I can't seem to figure out what the difference is between using
>=20
>   evaluate (runST action)
>=20
> and
>=20
>   stToIO action
>=20
> when in the IO monad and running something in ST...they seem to behave
> identically...are they?
>=20
> If they are, why do they have different type signatures (one is ST
> RealWorld a -> IO a, while the other is (forall s. ST s a) -> IO a)?

With stToIO, you can do this:

   do r <- stToIO newSTRef
      stToIO $ writeSTRef r 42
      ...

the types prevent you doing that with runST, but runST is safe to use in
pure code whereas stToIO must be used in the IO monad.

Cheers,
	Simon