John Meacham wrote:
On Sat, Nov 14, 2009 at 04:15:40PM -0800, John Meacham wrote:
In jhc, we would use something similar to what ghc does. the current IO definition is:
newtype IO a = IO (World__ -> (# World__, a #))
So, the only difference would be ST takes any state, not just the world, or
newtype ST s a = ST (s -> (# s, a #))
It occurs to me that something like this would be closer to the ghc way..
data State s :: # newtype ST s a = ST (State s -> (# State s, a #))
then making IO
newtype IO a = ST World__ a
but just the newtype around IO is probably a better first pass as it won't require mucking with the IO implementation. Plus it will be portable to other compilers that have unsafePerformIO...
well, it would be nice for such a "portable" implementation to exist... However, unsafePerformIO is often slower than an ST implementation has the potential to be (e.g. in GHC unsafePerformIO contains lots of safe-guards, each of which has been added after painful experience but which are not needed for ST itself). -Isaac