You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Could this MonadSTM type class be adopted by the stm package?
It would be useful for certain abstractions such as the "console region" defined in concurrent-output, which currently defines its own equivalent type class.
My use case involves a monad transformer atop such a thing; I want to write a type signature like:
(MonadReaderEnv m, MonadSTM m) => m ()
Reacted by Herbert Valerio Riedel, Alvaro Fernando García, Sean Hess, Nick Demming and Zsolt Szende
Is there any movement on this? Or is there another recommended path? It seems like wanting to have your TVars in a MonadReader instance would be a pretty common use case
I'm not sure if it's a good idea to provide instances for both STM and IO. Unlike MonadIO, it's not a monad homomorphism because liftRegion (a >>= k) and liftRegion m >>= liftRegion . k are completely different; hiding atomically semantics behind such abstraction seems like a footgun.
If the usecase is about monads like ReaderT Env STM, it should not have an instance for IO. Otherwise generalising atomically to MonadIO m => STM a -> m a seem like the right approach
Activity
simonmar commentedon Jun 17, 2019
Seems reasonable. Want to make a PR?
mitchellwrosen commentedon Jun 17, 2019
Sure
seanhess commentedon Nov 10, 2020
Is there any movement on this? Or is there another recommended path? It seems like wanting to have your TVars in a MonadReader instance would be a pretty common use case
mitchellwrosen commentedon Nov 13, 2020
As far as I can tell the PR is ready to merge
demming commentedon Mar 24, 2021
Hey, any updates on this issue? I too would love to use it from the stm package.
fumieval commentedon Jan 10, 2022
I'm not sure if it's a good idea to provide instances for both STM and IO. Unlike
MonadIO, it's not a monad homomorphism becauseliftRegion (a >>= k)andliftRegion m >>= liftRegion . kare completely different; hidingatomicallysemantics behind such abstraction seems like a footgun.If the usecase is about monads like
ReaderT Env STM, it should not have an instance for IO. Otherwise generalisingatomicallytoMonadIO m => STM a -> m aseem like the right approacharybczak commentedon Sep 6, 2026
You can, it's
(MonadReader Env m, MonadBase STM m) => m ()withMonadBasefromtransformers-base.