From d1c671f9dc44ed5be39c863787d0e764ea9a162c Mon Sep 17 00:00:00 2001 From: Bodigrim Date: Thu, 4 Jun 2026 00:00:56 +0100 Subject: [PATCH] Weaken Monad constraints of {eval,exec}StateT to Functor --- Control/Monad/Trans/State/Lazy.hs | 12 ++++-------- Control/Monad/Trans/State/Strict.hs | 12 ++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/Control/Monad/Trans/State/Lazy.hs b/Control/Monad/Trans/State/Lazy.hs index 460addd..4534027 100644 --- a/Control/Monad/Trans/State/Lazy.hs +++ b/Control/Monad/Trans/State/Lazy.hs @@ -167,20 +167,16 @@ newtype StateT s m a = StateT { runStateT :: s -> m (a,s) } -- and return the final value, discarding the final state. -- -- * @'evalStateT' m s = 'liftM' 'fst' ('runStateT' m s)@ -evalStateT :: (Monad m) => StateT s m a -> s -> m a -evalStateT m s = do - ~(a, _) <- runStateT m s - return a +evalStateT :: Functor m => StateT s m a -> s -> m a +evalStateT m s = (\(~(a, _)) -> a) <$> runStateT m s {-# INLINE evalStateT #-} -- | Evaluate a state computation with the given initial state -- and return the final state, discarding the final value. -- -- * @'execStateT' m s = 'liftM' 'snd' ('runStateT' m s)@ -execStateT :: (Monad m) => StateT s m a -> s -> m s -execStateT m s = do - ~(_, s') <- runStateT m s - return s' +execStateT :: Functor m => StateT s m a -> s -> m s +execStateT m s = (\(~(_, s')) -> s') <$> runStateT m s {-# INLINE execStateT #-} -- | Map both the return value and final state of a computation using diff --git a/Control/Monad/Trans/State/Strict.hs b/Control/Monad/Trans/State/Strict.hs index edd5549..92442ac 100644 --- a/Control/Monad/Trans/State/Strict.hs +++ b/Control/Monad/Trans/State/Strict.hs @@ -160,20 +160,16 @@ newtype StateT s m a = StateT { runStateT :: s -> m (a,s) } -- and return the final value, discarding the final state. -- -- * @'evalStateT' m s = 'liftM' 'fst' ('runStateT' m s)@ -evalStateT :: (Monad m) => StateT s m a -> s -> m a -evalStateT m s = do - (a, _) <- runStateT m s - return a +evalStateT :: Functor m => StateT s m a -> s -> m a +evalStateT m s = (\(a, _) -> a) <$> runStateT m s {-# INLINE evalStateT #-} -- | Evaluate a state computation with the given initial state -- and return the final state, discarding the final value. -- -- * @'execStateT' m s = 'liftM' 'snd' ('runStateT' m s)@ -execStateT :: (Monad m) => StateT s m a -> s -> m s -execStateT m s = do - (_, s') <- runStateT m s - return s' +execStateT :: Functor m => StateT s m a -> s -> m s +execStateT m s = (\(_, s') -> s') <$> runStateT m s {-# INLINE execStateT #-} -- | Map both the return value and final state of a computation using