diff --git a/Control/Monad/STM/Class.hs b/Control/Monad/STM/Class.hs new file mode 100644 index 0000000..4d2fbbd --- /dev/null +++ b/Control/Monad/STM/Class.hs @@ -0,0 +1,43 @@ +{-# LANGUAGE CPP #-} + +#if __GLASGOW_HASKELL__ >= 701 +{-# LANGUAGE Trustworthy #-} +#endif + +----------------------------------------------------------------------------- +-- | +-- Module : Control.Monad.STM +-- Copyright : (c) The University of Glasgow 2004 +-- License : BSD-style (see the file libraries/base/LICENSE) +-- +-- Maintainer : libraries@haskell.org +-- Stability : experimental +-- Portability : non-portable (requires STM) +-- +-- Class of monads based on @STM@. +----------------------------------------------------------------------------- + +module Control.Monad.STM.Class ( + MonadSTM(..) + ) where + +import GHC.Conc (STM) + + +-- | 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)@ +class Monad m => MonadSTM m where + -- | Lift a computation from the 'STM' monad. + liftSTM :: STM a -> m a + +-- | @since FIXME +instance MonadSTM STM where + liftSTM = id diff --git a/changelog.md b/changelog.md index bf8b44c..6e30871 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog for [`stm` package](http://hackage.haskell.org/package/stm) +## Unreleased + + * Added `Control.Monad.STM.Class` module + + * Before release, update `@since FIXME` annotations + ## 2.5.0.0 *Sep 2018* * Removed `alwaysSucceeds` and `always`, GHC's invariant checking primitives. (GHC #14324) diff --git a/stm.cabal b/stm.cabal index 36a2b30..aedd639 100644 --- a/stm.cabal +++ b/stm.cabal @@ -60,6 +60,7 @@ library Control.Concurrent.STM.TBQueue Control.Concurrent.STM.TSem Control.Monad.STM + Control.Monad.STM.Class other-modules: Control.Sequential.STM