
On February 2, 2009 11:26:02 Tyson Whitehead wrote:
The STT type above is a version of ST like the ReaderT, StateT, etc. types.
newtype STT s m a = STT ( State# s -> m (STTBox s a) ) data STTBox s a = STTBox {-#UNPACK#-} !(State# s) {-#UNPACK#-} !a
runSTT :: (Monad m) => (forall s. STT s m a) -> m a runSTT m = case m of STT m' -> do STTBox _ x <- m' realWorld# return x
instance Monad m => Monad (STT s m) where return x = STT $ \s -> return $ STTBox s x (STT m) >>= k = STT $ \s -> do STTBox s' x <- m s case k x of STT k' -> k' s'
Of course, I forgot the method to actually use state threaded code stToSTT :: Monad m => ST s a -> STT s m a stToSTT (ST m) = STT $ \s -> case m s of (# s',x #) -> return $ STTBox s' x In re-reading my original email, I also thought I might not have been clear that I did write the instance methods (MonadCont, etc.), I just didn't include them as they would have made the email too lengthy. Cheers! -Tyson PS: Thanks for all the comments so far.