@@ -51,9 +51,8 @@ module Effectful.Internal.Monad
5151 , getEffect
5252 , putEffect
5353 , stateEffect
54− , localEffect
55− , readerEffectM
5654 , stateEffectM
55+ , localEffect
5756 ) where
5857
5958import Control.Applicative (liftA2)
@@ -256,8 +255,9 @@ runFail m = unsafeEff $ \es0 -> mask $ \release -> do
256255 pure r
257256
258257instance Fail :> es => MonadFail (Eff es) where
259− fail msg = readerEffectM $ \(IdE (Fail tag)) -> unsafeEff_ $ do
260− throwIO $ FailEx tag msg
258+ fail msg = do
259+ IdE (Fail tag) <- getEffect
260+ unsafeEff_ . throwIO $ FailEx tag msg
261261
262262--------------------
263263
@@ -379,7 +379,9 @@ data Limit
379379
380380-- | Get the current 'UnliftStrategy'.
381381unliftStrategy :: IOE :> es => Eff es UnliftStrategy
382−unliftStrategy = readerEffectM $ \(IdE (IOE unlift)) -> pure unlift
382+unliftStrategy = do
383+ IdE (IOE unlift) <- getEffect
384+ pure unlift
383385
384386-- | Locally override the 'UnliftStrategy' with a given value.
385387--
@@ -430,22 +432,19 @@ getEffect :: e :> es => Eff es (handler e)
430432getEffect = unsafeEff $ \es -> getEnv es
431433
432434putEffect :: e :> es => handler e -> Eff es ()
433−putEffect e = unsafeEff $ \es -> unsafePutEnv e es
435+putEffect e = unsafeEff $ \es -> unsafePutEnv es e
434436
435437stateEffect :: e :> es => (handler e -> (a, handler e)) -> Eff es a
436−stateEffect f = unsafeEff $ \es -> unsafeStateEnv f es
437−
438−localEffect :: e :> es => (handler e -> handler e) -> Eff es a -> Eff es a
439−localEffect f m = unsafeEff $ \es -> do
440− bracket (unsafeStateEnv (\e -> (e, f e)) es)
441− (\e -> unsafePutEnv e es)
442− (\_ -> unEff m es)
443−
444−readerEffectM :: e :> es => (handler e -> Eff es a) -> Eff es a
445−readerEffectM f = unsafeEff $ \es -> getEnv es >>= \e -> unEff (f e) es
438+stateEffect f = unsafeEff $ \es -> unsafeStateEnv es f
446439
447440stateEffectM :: e :> es => (handler e -> Eff es (a, handler e)) -> Eff es a
448441stateEffectM f = unsafeEff $ \es -> mask $ \release -> do
449442 (a, e) <- (\e -> release $ unEff (f e) es) =<< getEnv es
450− unsafePutEnv e es
443+ unsafePutEnv es e
451444 pure a
445+
446+localEffect :: e :> es => (handler e -> handler e) -> Eff es a -> Eff es a
447+localEffect f m = unsafeEff $ \es -> do
448+ bracket (unsafeStateEnv es $ \e -> (e, f e))
449+ (\e -> unsafePutEnv es e)
450+ (\_ -> unEff m es)