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 { something; g }
fails to typecheck with Couldn't match type 'Data.Functor.Identity.Identity' with 'IO'
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With