|
| 1 | +{-# LANGUAGE CPP #-} |
| 2 | + |
| 3 | +#if __GLASGOW_HASKELL__ >= 701 |
| 4 | +{-# LANGUAGE Trustworthy #-} |
| 5 | +#endif |
| 6 | + |
| 7 | +----------------------------------------------------------------------------- |
| 8 | +-- | |
| 9 | +-- Module : Control.Monad.STM |
| 10 | +-- Copyright : (c) The University of Glasgow 2004 |
| 11 | +-- License : BSD-style (see the file libraries/base/LICENSE) |
| 12 | +-- |
| 13 | +-- Maintainer : libraries@haskell.org |
| 14 | +-- Stability : experimental |
| 15 | +-- Portability : non-portable (requires STM) |
| 16 | +-- |
| 17 | +-- Class of monads based on @STM@. |
| 18 | +----------------------------------------------------------------------------- |
| 19 | + |
| 20 | +module Control.Monad.STM.Class ( |
| 21 | + MonadSTM(..) |
| 22 | + ) where |
| 23 | + |
| 24 | +import GHC.Conc (STM, atomically) |
| 25 | + |
| 26 | + |
| 27 | +-- | Monads in which 'STM' computations may be embedded. |
| 28 | +-- Any monad built by applying a sequence of monad transformers to the |
| 29 | +-- 'STM' monad will be an instance of this class. |
| 30 | +-- |
| 31 | +-- Instances should satisfy the following laws, which state that 'liftSTM' |
| 32 | +-- is a transformer of monads: |
| 33 | +-- |
| 34 | +-- * @'liftSTM' . 'return' = 'return'@ |
| 35 | +-- |
| 36 | +-- * @'liftSTM' (m >>= f) = 'liftSTM' m >>= ('liftSTM' . f)@ |
| 37 | + |
| 38 | +class Monad m => MonadSTM m where |
| 39 | + -- | Lift a computation from the 'STM' monad. |
| 40 | + liftSTM :: STM a -> m a |
| 41 | + |
| 42 | +-- | @since FIXME |
| 43 | +instance MonadSTM STM where |
| 44 | + liftSTM = id |
| 45 | + |
| 46 | +-- | @since FIXME |
| 47 | +instance MonadSTM IO where |
| 48 | + liftSTM = atomically |
0 commit comments