Reputation: 39390
Basically, what I want is this:
stateIO :: (s -> IO (a, s)) -> StateT s IO a
stateIO f = do
r <- get
(a, r') <- liftIO $ f r
put r'
return a
I tried to use state
, but the inner liftIO
is problematic. Is there another way to be more clever, without that manual tuple unpacking?
Upvotes: 0
Views: 78
Reputation: 39390
Oh well. Thanks @bisserlis.
stateIO = StateT
(perhaps applied to avoid monomorphism restriction).
Upvotes: 2