@@ -3,30 +3,37 @@ module Countdown where
33
44import Data.Functor.Identity
55
6−import qualified Control.Monad.Reader as M
7−import qualified Control.Monad.State as M
6+-- eff
7+#ifdef VERSION_eff
8+import qualified Control.Effect as L
9+#endif
810
11+-- effective
912import qualified Effective as E
1013import qualified Effective.Reader as E
1114import qualified Effective.State as E
15+import qualified Effective.State.MVar as ME
1216import qualified Effective.State.Dynamic as DE
1317
18+-- freer-simple
1419#ifdef VERSION_freer_simple
1520import qualified Control.Monad.Freer as FS
1621import qualified Control.Monad.Freer.Reader as FS
1722import qualified Control.Monad.Freer.State as FS
1823#endif
1924
20−#ifdef VERSION_eff
21−import qualified Control.Effect as L
22−#endif
23−
25+-- fused-effects
2426#ifdef VERSION_fused_effects
2527import qualified Control.Algebra as FE
2628import qualified Control.Carrier.Reader as FE
2729import qualified Control.Carrier.State.Strict as FE
2830#endif
2931
32+-- mtl
33+import qualified Control.Monad.Reader as M
34+import qualified Control.Monad.State as M
35+
36+-- polysemy
3037#ifdef VERSION_polysemy
3138import qualified Polysemy as P
3239import qualified Polysemy.Reader as P
@@ -66,7 +73,7 @@ countdownMtlDeep n = runIdentity
6673 runR = flip M.runReaderT ()
6774
6875----------------------------------------
69−-- effective (static)
76+-- effective (pure)
7077
7178programEffectiveStatic :: E.State Integer E.:> es => E.Eff es Integer
7279programEffectiveStatic = do
@@ -90,6 +97,31 @@ countdownEffectiveStaticDeep n = E.runEff
9097 where
9198 runR = E.runReader ()
9299
100+----------------------------------------
101+-- effective (mvar)
102+
103+programEffectiveMVar :: ME.State Integer E.:> es => E.Eff es Integer
104+programEffectiveMVar = do
105+ n <- ME.get @Integer
106+ if n <= 0
107+ then pure n
108+ else do
109+ ME.put (n - 1)
110+ programEffectiveMVar
111+{-# NOINLINE programEffectiveMVar #-}
112+
113+countdownEffectiveMVar :: Integer -> IO (Integer, Integer)
114+countdownEffectiveMVar n = E.runEff . ME.runState n $ programEffectiveMVar
115+
116+countdownEffectiveMVarDeep :: Integer -> IO (Integer, Integer)
117+countdownEffectiveMVarDeep n = E.runEff
118+ . runR . runR . runR . runR . runR . runR . runR . runR . runR . runR
119+ . ME.runState n
120+ . runR . runR . runR . runR . runR . runR . runR . runR . runR . runR
121+ $ programEffectiveMVar
122+ where
123+ runR = E.runReader ()
124+
93125----------------------------------------
94126-- effective (dynamic)
95127
@@ -103,11 +135,14 @@ programEffectiveDynamic = do
103135 programEffectiveDynamic
104136{-# NOINLINE programEffectiveDynamic #-}
105137
106−countdownEffectiveDynamic :: Integer -> IO (Integer, Integer)
107−countdownEffectiveDynamic n = E.runEff . DE.runState n $ programEffectiveDynamic
138+countdownEffectiveDynPure :: Integer -> IO (Integer, Integer)
139+countdownEffectiveDynPure n = E.runEff . DE.runState n $ programEffectiveDynamic
140+
141+countdownEffectiveDynMVar :: Integer -> IO (Integer, Integer)
142+countdownEffectiveDynMVar n = E.runEff . DE.runStateMVar n $ programEffectiveDynamic
108143
109−countdownEffectiveDynamicDeep :: Integer -> IO (Integer, Integer)
110−countdownEffectiveDynamicDeep n = E.runEff
144+countdownEffectiveDynPureDeep :: Integer -> IO (Integer, Integer)
145+countdownEffectiveDynPureDeep n = E.runEff
111146 . runR . runR . runR . runR . runR . runR . runR . runR . runR . runR
112147 . DE.runState n
113148 . runR . runR . runR . runR . runR . runR . runR . runR . runR . runR
@@ -115,6 +150,15 @@ countdownEffectiveDynamicDeep n = E.runEff
115150 where
116151 runR = E.runReader ()
117152
153+countdownEffectiveDynMVarDeep :: Integer -> IO (Integer, Integer)
154+countdownEffectiveDynMVarDeep n = E.runEff
155+ . runR . runR . runR . runR . runR . runR . runR . runR . runR . runR
156+ . DE.runStateMVar n
157+ . runR . runR . runR . runR . runR . runR . runR . runR . runR . runR
158+ $ programEffectiveDynamic
159+ where
160+ runR = E.runReader ()
161+
118162----------------------------------------
119163-- fused-effects
120164