{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Control.Monad.Class.MonadST (MonadST (..)) where
import Control.Monad.Reader
import Control.Monad.Primitive
import Control.Monad.ST as ST (ST, stToIO)
class Monad m => MonadST m where
stToIO :: ST (PrimState m) a -> m a
withLiftST :: (forall s. (forall a. ST s a -> m a) -> b) -> b
{-# DEPRECATED withLiftST "Use the simpler 'stToIO' instead." #-}
instance MonadST IO where
stToIO :: forall a. ST (PrimState IO) a -> IO a
stToIO = ST (PrimState IO) a -> IO a
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim
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 a. ST RealWorld a -> IO a) -> b
forall s. (forall a. ST s a -> IO a) -> b
f ST RealWorld a -> IO a
forall a. ST RealWorld a -> IO a
ST.stToIO
instance MonadST (ST s) where
stToIO :: forall a. ST (PrimState (ST s)) a -> ST s a
stToIO = ST (PrimState (ST s)) a -> ST s a
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim
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 a. ST s a -> ST s a) -> b
forall s. (forall a. ST s a -> ST s a) -> b
f ST s a -> ST s a
forall a. a -> a
forall a. ST s a -> ST s a
id
instance (MonadST m, PrimMonad m) => MonadST (ReaderT r m) where
stToIO :: ST (PrimState m) a -> ReaderT r m a
stToIO :: forall a. ST (PrimState m) a -> ReaderT r m a
stToIO ST (PrimState m) a
f = m a -> ReaderT r m a
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ST (PrimState m) a -> m a
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim ST (PrimState m) a
f)
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 s. (forall a. ST s a -> m a) -> b) -> b
forall b. (forall s. (forall a. ST s a -> m a) -> b) -> b
forall (m :: * -> *) b.
MonadST m =>
(forall s. (forall a. ST s a -> m a) -> b) -> b
withLiftST ((forall s. (forall a. ST s a -> m a) -> b) -> b)
-> (forall s. (forall a. ST s a -> m a) -> b) -> b
forall a b. (a -> b) -> a -> b
$ \forall a. ST s a -> m a
g -> (forall a. ST s a -> ReaderT r m a) -> b
forall s. (forall a. ST s a -> ReaderT r m a) -> b
f (m a -> ReaderT r m a
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ReaderT r m a)
-> (ST s a -> m a) -> ST s a -> ReaderT r m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ST s a -> m a
forall a. ST s a -> m a
g)