Combining StateT IO with State

后端 未结 1 1998
野趣味
野趣味 2020-12-31 09:50

If I have a function f :: State Int (), is it possible to use it within another function g :: StateT Int IO ()? Nesting it with f = do { some

相关标签:
1条回答
  • 2020-12-31 10:11

    Yes, this operation is usually called "hoisting". For the State monad, it could be defined as

    hoistState :: Monad m => State s a -> StateT s m a
    hoistState = state . runState
    

    Unfortunately, it is not defined in the Control.Monad.State module.

    0 讨论(0)
提交回复
热议问题