Skip to content

Commit

Permalink
Add Control.Monad.STM.Class
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellwrosen committed Jun 17, 2019
1 parent 3860cd1 commit 5d0f5c5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Control/Monad/STM/Class.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{-# 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 : [email protected]
-- Stability : experimental
-- Portability : non-portable (requires STM)
--
-- Class of monads based on @STM@.
-----------------------------------------------------------------------------

module Control.Monad.STM.Class (
MonadSTM(..)
) where

import GHC.Conc (STM, atomically)


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

-- | @since FIXME
instance MonadSTM IO where
liftSTM = atomically
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions stm.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5d0f5c5

Please sign in to comment.