{-# LANGUAGE RankNTypes #-}
module Control.Monad.Class.MonadST (MonadST (..)) where
import Control.Monad.Reader
import Control.Monad.ST (ST, stToIO)
class Monad m => MonadST m where
withLiftST :: (forall s. (forall a. ST s a -> m a) -> b) -> b
instance MonadST IO where
withLiftST :: forall b. (forall s. (forall a. ST s a -> IO a) -> b) -> b
withLiftST = \forall s. (forall a. ST s a -> IO a) -> b
f -> forall s. (forall a. ST s a -> IO a) -> b
f forall a. ST RealWorld a -> IO a
stToIO
instance MonadST (ST s) where
withLiftST :: forall b. (forall s. (forall a. ST s a -> ST s a) -> b) -> b
withLiftST = \forall s. (forall a. ST s a -> ST s a) -> b
f -> forall s. (forall a. ST s a -> ST s a) -> b
f forall a. a -> a
id
instance MonadST m => MonadST (ReaderT r m) where
withLiftST :: forall b. (forall s. (forall a. ST s a -> ReaderT r m a) -> b) -> b
withLiftST forall s. (forall a. ST s a -> ReaderT r m a) -> b
f = forall (m :: * -> *) b.
MonadST m =>
(forall s. (forall a. ST s a -> m a) -> b) -> b
withLiftST forall a b. (a -> b) -> a -> b
$ \forall a. ST s a -> m a
g -> forall s. (forall a. ST s a -> ReaderT r m a) -> b
f (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ST s a -> m a
g)