stm
stm copied to clipboard
Add Control.Monad.STM.Class
Addresses #22
This patch adds a new module Control.Monad.STM.Class that exposes a MonadSTM type class and instances for STM and IO. I lifted the haddocks directly from MonadIO.
Whoops, just realized that the MonadIO docs do not fully translate to STM. Specifically, this "law":
liftSTM (m >>= f) = liftSTM m >>= (liftSTM . f)
This is ready to go aside from the documentation nit. If anyone has advice on how we might want to re-word this (or not) I'm all ears:
-- | Monads in which 'STM' computations may be embedded.
-- Any monad built by applying a sequence of monad transformers to the
-- 'STM' monad will be an instance of this class.
--
-- Instances should satisfy the following laws, which state that 'liftSTM'
-- is a transformer of monads:
--
-- * @'liftSTM' . 'return' = 'return'@
--
-- * @'liftSTM' (m >>= f) = 'liftSTM' m >>= ('liftSTM' . f)@
What's the issue specifically?
Oh, just that for IO monads, liftSTM wraps a transaction, so it seems odd to suggest that liftSTM m >>= f) (one transaction) is equivalent to liftSTM m >>= liftSTM . f (two transactions).
Should there even be an instance MonadSTM IO? It seems dubious to me.
I definitely agree that the MonadSTM IO instance is a massive foot-gun.
Removed =)
@simonmar, any objection to merging this?
What's the plan for providing instances for transformers?
@simonmar, any objection to merging this?
no objections. Needs updating to resolve conflicts though.