stm icon indicating copy to clipboard operation
stm copied to clipboard

Add Control.Monad.STM.Class

Open mitchellwrosen opened this issue 6 years ago • 10 comments
trafficstars

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.

mitchellwrosen avatar Jun 17 '19 17:06 mitchellwrosen

Whoops, just realized that the MonadIO docs do not fully translate to STM. Specifically, this "law":

liftSTM (m >>= f) = liftSTM m >>= (liftSTM . f)

mitchellwrosen avatar Jun 17 '19 17:06 mitchellwrosen

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)@

mitchellwrosen avatar Jun 18 '19 13:06 mitchellwrosen

What's the issue specifically?

simonmar avatar Jun 27 '19 07:06 simonmar

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).

mitchellwrosen avatar Jun 27 '19 14:06 mitchellwrosen

Should there even be an instance MonadSTM IO? It seems dubious to me.

simonmar avatar Jul 01 '19 07:07 simonmar

I definitely agree that the MonadSTM IO instance is a massive foot-gun.

bgamari avatar Oct 15 '19 20:10 bgamari

Removed =)

mitchellwrosen avatar Oct 17 '19 01:10 mitchellwrosen

@simonmar, any objection to merging this?

bgamari avatar Mar 24 '21 22:03 bgamari

What's the plan for providing instances for transformers?

fumieval avatar Jan 10 '22 05:01 fumieval

@simonmar, any objection to merging this?

no objections. Needs updating to resolve conflicts though.

simonmar avatar Jan 11 '22 14:01 simonmar