@@ -51,9 +51,8 @@ module Effectful.Internal.Monad
51 , getEffect
51 , getEffect
52 , putEffect
52 , putEffect
53 , stateEffect
53 , stateEffect
56 , stateEffectM
54 , stateEffectM
59import Control.Applicative (liftA2)
58import Control.Applicative (liftA2)
@@ -256,8 +255,9 @@ runFail m = unsafeEff $ \es0 -> mask $ \release -> do
258instance Fail :> es => MonadFail (Eff es) where
257instance Fail :> es => MonadFail (Eff es) where
259− fail msg = readerEffectM $ \(IdE (Fail tag)) -> unsafeEff_ $ do
258+ fail msg = do
259+ IdE (Fail tag) <- getEffect
260− throwIO $ FailEx tag msg
260+ unsafeEff_ . throwIO $ FailEx tag msg
262--------------------
262--------------------
@@ -379,7 +379,9 @@ data Limit
380-- | Get the current 'UnliftStrategy'.
380-- | Get the current 'UnliftStrategy'.
381unliftStrategy :: IOE :> es => Eff es UnliftStrategy
381unliftStrategy :: IOE :> es => Eff es UnliftStrategy
382−unliftStrategy = readerEffectM $ \(IdE (IOE unlift)) -> pure unlift
382+unliftStrategy = do
383+ IdE (IOE unlift) <- getEffect
384-- | Locally override the 'UnliftStrategy' with a given value.
386-- | Locally override the 'UnliftStrategy' with a given value.
@@ -430,22 +432,19 @@ getEffect :: e :> es => Eff es (handler e)
430getEffect = unsafeEff $ \es -> getEnv es
432getEffect = unsafeEff $ \es -> getEnv es
432putEffect :: e :> es => handler e -> Eff es ()
434putEffect :: e :> es => handler e -> Eff es ()
433−putEffect e = unsafeEff $ \es -> unsafePutEnv e es
435+putEffect e = unsafeEff $ \es -> unsafePutEnv es e
435stateEffect :: e :> es => (handler e -> (a, handler e)) -> Eff es a
437stateEffect :: e :> es => (handler e -> (a, handler e)) -> Eff es a
436−stateEffect f = unsafeEff $ \es -> unsafeStateEnv f es
438+stateEffect f = unsafeEff $ \es -> unsafeStateEnv es f
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)
444−readerEffectM :: e :> es => (handler e -> Eff es a) -> Eff es a
445−readerEffectM f = unsafeEff $ \es -> getEnv es >>= \e -> unEff (f e) es
447stateEffectM :: e :> es => (handler e -> Eff es (a, handler e)) -> Eff es a
440stateEffectM :: e :> es => (handler e -> Eff es (a, handler e)) -> Eff es a
448stateEffectM f = unsafeEff $ \es -> mask $ \release -> do
441stateEffectM f = unsafeEff $ \es -> mask $ \release -> do
449 (a, e) <- (\e -> release $ unEff (f e) es) =<< getEnv es
442 (a, e) <- (\e -> release $ unEff (f e) es) =<< getEnv es
450− unsafePutEnv e es
443+ unsafePutEnv es e
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)