how to implement mapAccumM?
===

I want mapM over something that is traversible while passing an accumulator. I came up with:

    import Control.Applicative
    import Data.Traversable
    import Control.Monad.State

    mapAccumM :: (Applicative m, Traversable t, MonadState s m)
                 => (s -> a -> m (s, b)) -> s -> t a -> m (t b)
    mapAccumM f acc0 xs = put acc0 >> traverse g xs
      where
        g x = do
          oldAcc <- get
          (newAcc, y) <- f oldAcc x
          put newAcc
          return y

How can this be done without State monad?