[Haskell-cafe] Composing functions with runST

Yitzchak Gale gale at sefer.org
Thu Jan 4 08:10:45 EST 2007

I wrote:
> Am I missing something?

Yes! In reality, I do not need unsafeSTRef for this
at all, using a type suggested earlier by Udo:

stToState :: MonadState st m => (forall s. STRef s st -> ST s a) -> m a
stToState f = do
    s <- get
    let (y, s') = runST (stm f s)
    put s'
    return y
    stm f s = do
      r <- newSTRef s
      y <- f r
      s' <- readSTRef r
      return (y, s')

This works! Thanks, Udo!


More information about the Haskell-Cafe mailing list