Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Control.Monad.STM.Class #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mitchellwrosen
Copy link
Contributor

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
Copy link
Contributor Author

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

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

@mitchellwrosen
Copy link
Contributor Author

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

@simonmar
Copy link
Member

What's the issue specifically?

@mitchellwrosen
Copy link
Contributor Author

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

@simonmar
Copy link
Member

simonmar commented Jul 1, 2019

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

@bgamari
Copy link
Contributor

bgamari commented Oct 15, 2019

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

@mitchellwrosen
Copy link
Contributor Author

Removed =)

@bgamari
Copy link
Contributor

bgamari commented Mar 24, 2021

@simonmar, any objection to merging this?

@fumieval
Copy link

What's the plan for providing instances for transformers?

@simonmar
Copy link
Member

@simonmar, any objection to merging this?

no objections. Needs updating to resolve conflicts though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants