{-# LANGUAGE GeneralizedNewtypeDeriving, MultiParamTypeClasses, RankNTypes, TypeOperators, UndecidableInstances #-}
module Control.Effect.Interpret
( runInterpret
, InterpretC(..)
, runInterpretState
, InterpretStateC(..)
) where

import Control.Applicative (Alternative(..))
import Control.Effect.Carrier
import Control.Effect.Reader
import Control.Effect.State
import Control.Monad (MonadPlus(..))
import qualified Control.Monad.Fail as Fail
import Control.Monad.Fix
import Control.Monad.IO.Class
import Control.Monad.Trans.Class

-- | Interpret an effect using a higher-order function.
--
--   This involves a great deal less boilerplate than defining a custom 'Carrier' instance, at the expense of somewhat less performance. It’s a reasonable starting point for new interpretations, and if more performance or flexibility is required, it’s straightforward to “graduate” by replacing the relevant 'runInterpret' handlers with specialized 'Carrier' instances for the effects.
--
--   At time of writing, a simple passthrough use of 'runInterpret' to handle a 'State' effect is about five times slower than using 'StateC' directly.
--
--   prop> run (runInterpret (\ op -> case op of { Get k -> k a ; Put _ k -> k }) get) === a
runInterpret :: (forall x . eff m x -> m x) -> InterpretC eff m a -> m a
runInterpret :: (forall x. eff m x -> m x) -> InterpretC eff m a -> m a
runInterpret handler :: forall x. eff m x -> m x
handler = Handler eff m -> ReaderC (Handler eff m) m a -> m a
forall r (m :: * -> *) a. r -> ReaderC r m a -> m a
runReader ((forall x. eff m x -> m x) -> Handler eff m
forall (eff :: (* -> *) -> * -> *) (m :: * -> *).
(forall x. eff m x -> m x) -> Handler eff m
Handler forall x. eff m x -> m x
handler) (ReaderC (Handler eff m) m a -> m a)
-> (InterpretC eff m a -> ReaderC (Handler eff m) m a)
-> InterpretC eff m a
-> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InterpretC eff m a -> ReaderC (Handler eff m) m a
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
InterpretC eff m a -> ReaderC (Handler eff m) m a
runInterpretC

newtype InterpretC eff m a = InterpretC { InterpretC eff m a -> ReaderC (Handler eff m) m a
runInterpretC :: ReaderC (Handler eff m) m a }
  deriving (Applicative (InterpretC eff m)
InterpretC eff m a
Applicative (InterpretC eff m) =>
(forall a. InterpretC eff m a)
-> (forall a.
    InterpretC eff m a -> InterpretC eff m a -> InterpretC eff m a)
-> (forall a. InterpretC eff m a -> InterpretC eff m [a])
-> (forall a. InterpretC eff m a -> InterpretC eff m [a])
-> Alternative (InterpretC eff m)
InterpretC eff m a -> InterpretC eff m a -> InterpretC eff m a
InterpretC eff m a -> InterpretC eff m [a]
InterpretC eff m a -> InterpretC eff m [a]
forall a. InterpretC eff m a
forall a. InterpretC eff m a -> InterpretC eff m [a]
forall a.
InterpretC eff m a -> InterpretC eff m a -> InterpretC eff m a
forall (f :: * -> *).
Applicative f =>
(forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
forall (eff :: (* -> *) -> * -> *) (m :: * -> *).
Alternative m =>
Applicative (InterpretC eff m)
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative m =>
InterpretC eff m a
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative m =>
InterpretC eff m a -> InterpretC eff m [a]
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative m =>
InterpretC eff m a -> InterpretC eff m a -> InterpretC eff m a
many :: InterpretC eff m a -> InterpretC eff m [a]
$cmany :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative m =>
InterpretC eff m a -> InterpretC eff m [a]
some :: InterpretC eff m a -> InterpretC eff m [a]
$csome :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative m =>
InterpretC eff m a -> InterpretC eff m [a]
<|> :: InterpretC eff m a -> InterpretC eff m a -> InterpretC eff m a
$c<|> :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative m =>
InterpretC eff m a -> InterpretC eff m a -> InterpretC eff m a
empty :: InterpretC eff m a
$cempty :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
Alternative m =>
InterpretC eff m a
$cp1Alternative :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *).
Alternative m =>
Applicative (InterpretC eff m)
Alternative, Functor (InterpretC eff m)
a -> InterpretC eff m a
Functor (InterpretC eff m) =>
(forall a. a -> InterpretC eff m a)
-> (forall a b.
    InterpretC eff m (a -> b)
    -> InterpretC eff m a -> InterpretC eff m b)
-> (forall a b c.
    (a -> b -> c)
    -> InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m c)
-> (forall a b.
    InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m b)
-> (forall a b.
    InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m a)
-> Applicative (InterpretC eff m)
InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m b
InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m a
InterpretC eff m (a -> b)
-> InterpretC eff m a -> InterpretC eff m b
(a -> b -> c)
-> InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m c
forall a. a -> InterpretC eff m a
forall a b.
InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m a
forall a b.
InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m b
forall a b.
InterpretC eff m (a -> b)
-> InterpretC eff m a -> InterpretC eff m b
forall a b c.
(a -> b -> c)
-> InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall (eff :: (* -> *) -> * -> *) (m :: * -> *).
Applicative m =>
Functor (InterpretC eff m)
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
Applicative m =>
a -> InterpretC eff m a
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a b.
Applicative m =>
InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m a
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a b.
Applicative m =>
InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m b
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a b.
Applicative m =>
InterpretC eff m (a -> b)
-> InterpretC eff m a -> InterpretC eff m b
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m c
<* :: InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m a
$c<* :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a b.
Applicative m =>
InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m a
*> :: InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m b
$c*> :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a b.
Applicative m =>
InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m b
liftA2 :: (a -> b -> c)
-> InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m c
$cliftA2 :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m c
<*> :: InterpretC eff m (a -> b)
-> InterpretC eff m a -> InterpretC eff m b
$c<*> :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a b.
Applicative m =>
InterpretC eff m (a -> b)
-> InterpretC eff m a -> InterpretC eff m b
pure :: a -> InterpretC eff m a
$cpure :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
Applicative m =>
a -> InterpretC eff m a
$cp1Applicative :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *).
Applicative m =>
Functor (InterpretC eff m)
Applicative, a -> InterpretC eff m b -> InterpretC eff m a
(a -> b) -> InterpretC eff m a -> InterpretC eff m b
(forall a b. (a -> b) -> InterpretC eff m a -> InterpretC eff m b)
-> (forall a b. a -> InterpretC eff m b -> InterpretC eff m a)
-> Functor (InterpretC eff m)
forall a b. a -> InterpretC eff m b -> InterpretC eff m a
forall a b. (a -> b) -> InterpretC eff m a -> InterpretC eff m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a b.
Functor m =>
a -> InterpretC eff m b -> InterpretC eff m a
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a b.
Functor m =>
(a -> b) -> InterpretC eff m a -> InterpretC eff m b
<$ :: a -> InterpretC eff m b -> InterpretC eff m a
$c<$ :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a b.
Functor m =>
a -> InterpretC eff m b -> InterpretC eff m a
fmap :: (a -> b) -> InterpretC eff m a -> InterpretC eff m b
$cfmap :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a b.
Functor m =>
(a -> b) -> InterpretC eff m a -> InterpretC eff m b
Functor, Applicative (InterpretC eff m)
a -> InterpretC eff m a
Applicative (InterpretC eff m) =>
(forall a b.
 InterpretC eff m a
 -> (a -> InterpretC eff m b) -> InterpretC eff m b)
-> (forall a b.
    InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m b)
-> (forall a. a -> InterpretC eff m a)
-> Monad (InterpretC eff m)
InterpretC eff m a
-> (a -> InterpretC eff m b) -> InterpretC eff m b
InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m b
forall a. a -> InterpretC eff m a
forall a b.
InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m b
forall a b.
InterpretC eff m a
-> (a -> InterpretC eff m b) -> InterpretC eff m b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
forall (eff :: (* -> *) -> * -> *) (m :: * -> *).
Monad m =>
Applicative (InterpretC eff m)
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
Monad m =>
a -> InterpretC eff m a
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a b.
Monad m =>
InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m b
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a b.
Monad m =>
InterpretC eff m a
-> (a -> InterpretC eff m b) -> InterpretC eff m b
return :: a -> InterpretC eff m a
$creturn :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
Monad m =>
a -> InterpretC eff m a
>> :: InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m b
$c>> :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a b.
Monad m =>
InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m b
>>= :: InterpretC eff m a
-> (a -> InterpretC eff m b) -> InterpretC eff m b
$c>>= :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a b.
Monad m =>
InterpretC eff m a
-> (a -> InterpretC eff m b) -> InterpretC eff m b
$cp1Monad :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *).
Monad m =>
Applicative (InterpretC eff m)
Monad, Monad (InterpretC eff m)
Monad (InterpretC eff m) =>
(forall a. String -> InterpretC eff m a)
-> MonadFail (InterpretC eff m)
String -> InterpretC eff m a
forall a. String -> InterpretC eff m a
forall (m :: * -> *).
Monad m =>
(forall a. String -> m a) -> MonadFail m
forall (eff :: (* -> *) -> * -> *) (m :: * -> *).
MonadFail m =>
Monad (InterpretC eff m)
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadFail m =>
String -> InterpretC eff m a
fail :: String -> InterpretC eff m a
$cfail :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadFail m =>
String -> InterpretC eff m a
$cp1MonadFail :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *).
MonadFail m =>
Monad (InterpretC eff m)
Fail.MonadFail, Monad (InterpretC eff m)
Monad (InterpretC eff m) =>
(forall a. (a -> InterpretC eff m a) -> InterpretC eff m a)
-> MonadFix (InterpretC eff m)
(a -> InterpretC eff m a) -> InterpretC eff m a
forall a. (a -> InterpretC eff m a) -> InterpretC eff m a
forall (m :: * -> *).
Monad m =>
(forall a. (a -> m a) -> m a) -> MonadFix m
forall (eff :: (* -> *) -> * -> *) (m :: * -> *).
MonadFix m =>
Monad (InterpretC eff m)
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadFix m =>
(a -> InterpretC eff m a) -> InterpretC eff m a
mfix :: (a -> InterpretC eff m a) -> InterpretC eff m a
$cmfix :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadFix m =>
(a -> InterpretC eff m a) -> InterpretC eff m a
$cp1MonadFix :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *).
MonadFix m =>
Monad (InterpretC eff m)
MonadFix, Monad (InterpretC eff m)
Monad (InterpretC eff m) =>
(forall a. IO a -> InterpretC eff m a)
-> MonadIO (InterpretC eff m)
IO a -> InterpretC eff m a
forall a. IO a -> InterpretC eff m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> MonadIO m
forall (eff :: (* -> *) -> * -> *) (m :: * -> *).
MonadIO m =>
Monad (InterpretC eff m)
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadIO m =>
IO a -> InterpretC eff m a
liftIO :: IO a -> InterpretC eff m a
$cliftIO :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
MonadIO m =>
IO a -> InterpretC eff m a
$cp1MonadIO :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *).
MonadIO m =>
Monad (InterpretC eff m)
MonadIO, Monad (InterpretC eff m)
Alternative (InterpretC eff m)
InterpretC eff m a
(Alternative (InterpretC eff m), Monad (InterpretC eff m)) =>
(forall a. InterpretC eff m a)
-> (forall a.
    InterpretC eff m a -> InterpretC eff m a -> InterpretC eff m a)
-> MonadPlus (InterpretC eff m)
InterpretC eff m a -> InterpretC eff m a -> InterpretC eff m a
forall a. InterpretC eff m a
forall a.
InterpretC eff m a -> InterpretC eff m a -> InterpretC eff m a
forall (m :: * -> *).
(Alternative m, Monad m) =>
(forall a. m a) -> (forall a. m a -> m a -> m a) -> MonadPlus m
forall (eff :: (* -> *) -> * -> *) (m :: * -> *).
(Alternative m, Monad m) =>
Monad (InterpretC eff m)
forall (eff :: (* -> *) -> * -> *) (m :: * -> *).
(Alternative m, Monad m) =>
Alternative (InterpretC eff m)
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
(Alternative m, Monad m) =>
InterpretC eff m a
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
(Alternative m, Monad m) =>
InterpretC eff m a -> InterpretC eff m a -> InterpretC eff m a
mplus :: InterpretC eff m a -> InterpretC eff m a -> InterpretC eff m a
$cmplus :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
(Alternative m, Monad m) =>
InterpretC eff m a -> InterpretC eff m a -> InterpretC eff m a
mzero :: InterpretC eff m a
$cmzero :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
(Alternative m, Monad m) =>
InterpretC eff m a
$cp2MonadPlus :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *).
(Alternative m, Monad m) =>
Monad (InterpretC eff m)
$cp1MonadPlus :: forall (eff :: (* -> *) -> * -> *) (m :: * -> *).
(Alternative m, Monad m) =>
Alternative (InterpretC eff m)
MonadPlus)

instance MonadTrans (InterpretC eff) where
  lift :: m a -> InterpretC eff m a
lift = ReaderC (Handler eff m) m a -> InterpretC eff m a
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
ReaderC (Handler eff m) m a -> InterpretC eff m a
InterpretC (ReaderC (Handler eff m) m a -> InterpretC eff m a)
-> (m a -> ReaderC (Handler eff m) m a)
-> m a
-> InterpretC eff m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> ReaderC (Handler eff m) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift
  {-# INLINE lift #-}

newtype Handler eff m = Handler (forall x . eff m x -> m x)

runHandler :: (HFunctor eff, Functor m) => Handler eff m -> eff (InterpretC eff m) a -> m a
runHandler :: Handler eff m -> eff (InterpretC eff m) a -> m a
runHandler h :: Handler eff m
h@(Handler handler :: forall x. eff m x -> m x
handler) = eff m a -> m a
forall x. eff m x -> m x
handler (eff m a -> m a)
-> (eff (InterpretC eff m) a -> eff m a)
-> eff (InterpretC eff m) a
-> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall x. InterpretC eff m x -> m x)
-> eff (InterpretC eff m) a -> eff m a
forall (h :: (* -> *) -> * -> *) (m :: * -> *) (n :: * -> *) a.
(HFunctor h, Functor m) =>
(forall x. m x -> n x) -> h m a -> h n a
hmap (Handler eff m -> ReaderC (Handler eff m) m x -> m x
forall r (m :: * -> *) a. r -> ReaderC r m a -> m a
runReader Handler eff m
h (ReaderC (Handler eff m) m x -> m x)
-> (InterpretC eff m x -> ReaderC (Handler eff m) m x)
-> InterpretC eff m x
-> m x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InterpretC eff m x -> ReaderC (Handler eff m) m x
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
InterpretC eff m a -> ReaderC (Handler eff m) m a
runInterpretC)

instance (HFunctor eff, Carrier sig m) => Carrier (eff :+: sig) (InterpretC eff m) where
  eff :: (:+:) eff sig (InterpretC eff m) a -> InterpretC eff m a
eff (L op :: eff (InterpretC eff m) a
op) = do
    Handler eff m
handler <- ReaderC (Handler eff m) m (Handler eff m)
-> InterpretC eff m (Handler eff m)
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
ReaderC (Handler eff m) m a -> InterpretC eff m a
InterpretC ReaderC (Handler eff m) m (Handler eff m)
forall r (sig :: (* -> *) -> * -> *) (m :: * -> *).
(Member (Reader r) sig, Carrier sig m) =>
m r
ask
    m a -> InterpretC eff m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Handler eff m -> eff (InterpretC eff m) a -> m a
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
(HFunctor eff, Functor m) =>
Handler eff m -> eff (InterpretC eff m) a -> m a
runHandler Handler eff m
handler eff (InterpretC eff m) a
op)
  eff (R other :: sig (InterpretC eff m) a
other) = ReaderC (Handler eff m) m a -> InterpretC eff m a
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) a.
ReaderC (Handler eff m) m a -> InterpretC eff m a
InterpretC ((:+:) (Reader (Handler eff m)) sig (ReaderC (Handler eff m) m) a
-> ReaderC (Handler eff m) m a
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Carrier sig m =>
sig m a -> m a
eff (sig (ReaderC (Handler eff m) m) a
-> (:+:) (Reader (Handler eff m)) sig (ReaderC (Handler eff m) m) a
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
g m k -> (:+:) f g m k
R (sig (InterpretC eff m) a -> sig (ReaderC (Handler eff m) m) a
forall (sig :: (* -> *) -> * -> *) (f :: * -> *) (g :: * -> *) a.
(HFunctor sig, Functor f, Coercible f g) =>
sig f a -> sig g a
handleCoercible sig (InterpretC eff m) a
other)))
  {-# INLINE eff #-}


-- | Interpret an effect using a higher-order function with some state variable.
--
--   This involves a great deal less boilerplate than defining a custom 'Carrier' instance, at the expense of somewhat less performance. It’s a reasonable starting point for new interpretations, and if more performance or flexibility is required, it’s straightforward to “graduate” by replacing the relevant 'runInterpretState' handlers with specialized 'Carrier' instances for the effects.
--
--   At time of writing, a simple use of 'runInterpretState' to handle a 'State' effect is about four times slower than using 'StateC' directly.
--
--   prop> run (runInterpretState (\ s op -> case op of { Get k -> runState s (k s) ; Put s' k -> runState s' k }) a get) === a
runInterpretState :: (forall x . s -> eff (StateC s m) x -> m (s, x)) -> s -> InterpretStateC eff s m a -> m (s, a)
runInterpretState :: (forall x. s -> eff (StateC s m) x -> m (s, x))
-> s -> InterpretStateC eff s m a -> m (s, a)
runInterpretState handler :: forall x. s -> eff (StateC s m) x -> m (s, x)
handler state :: s
state = s -> StateC s m a -> m (s, a)
forall s (m :: * -> *) a. s -> StateC s m a -> m (s, a)
runState s
state (StateC s m a -> m (s, a))
-> (InterpretStateC eff s m a -> StateC s m a)
-> InterpretStateC eff s m a
-> m (s, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HandlerState eff s m
-> ReaderC (HandlerState eff s m) (StateC s m) a -> StateC s m a
forall r (m :: * -> *) a. r -> ReaderC r m a -> m a
runReader ((forall x. eff (StateC s m) x -> StateC s m x)
-> HandlerState eff s m
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *).
(forall x. eff (StateC s m) x -> StateC s m x)
-> HandlerState eff s m
HandlerState (\ eff :: eff (StateC s m) x
eff -> (s -> m (s, x)) -> StateC s m x
forall s (m :: * -> *) a. (s -> m (s, a)) -> StateC s m a
StateC (\ s :: s
s -> s -> eff (StateC s m) x -> m (s, x)
forall x. s -> eff (StateC s m) x -> m (s, x)
handler s
s eff (StateC s m) x
eff))) (ReaderC (HandlerState eff s m) (StateC s m) a -> StateC s m a)
-> (InterpretStateC eff s m a
    -> ReaderC (HandlerState eff s m) (StateC s m) a)
-> InterpretStateC eff s m a
-> StateC s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InterpretStateC eff s m a
-> ReaderC (HandlerState eff s m) (StateC s m) a
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
InterpretStateC eff s m a
-> ReaderC (HandlerState eff s m) (StateC s m) a
runInterpretStateC

newtype InterpretStateC eff s m a = InterpretStateC { InterpretStateC eff s m a
-> ReaderC (HandlerState eff s m) (StateC s m) a
runInterpretStateC :: ReaderC (HandlerState eff s m) (StateC s m) a }
  deriving (Applicative (InterpretStateC eff s m)
InterpretStateC eff s m a
Applicative (InterpretStateC eff s m) =>
(forall a. InterpretStateC eff s m a)
-> (forall a.
    InterpretStateC eff s m a
    -> InterpretStateC eff s m a -> InterpretStateC eff s m a)
-> (forall a.
    InterpretStateC eff s m a -> InterpretStateC eff s m [a])
-> (forall a.
    InterpretStateC eff s m a -> InterpretStateC eff s m [a])
-> Alternative (InterpretStateC eff s m)
InterpretStateC eff s m a
-> InterpretStateC eff s m a -> InterpretStateC eff s m a
InterpretStateC eff s m a -> InterpretStateC eff s m [a]
InterpretStateC eff s m a -> InterpretStateC eff s m [a]
forall a. InterpretStateC eff s m a
forall a. InterpretStateC eff s m a -> InterpretStateC eff s m [a]
forall a.
InterpretStateC eff s m a
-> InterpretStateC eff s m a -> InterpretStateC eff s m a
forall (f :: * -> *).
Applicative f =>
(forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *).
(Alternative m, Monad m) =>
Applicative (InterpretStateC eff s m)
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
(Alternative m, Monad m) =>
InterpretStateC eff s m a
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
(Alternative m, Monad m) =>
InterpretStateC eff s m a -> InterpretStateC eff s m [a]
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
(Alternative m, Monad m) =>
InterpretStateC eff s m a
-> InterpretStateC eff s m a -> InterpretStateC eff s m a
many :: InterpretStateC eff s m a -> InterpretStateC eff s m [a]
$cmany :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
(Alternative m, Monad m) =>
InterpretStateC eff s m a -> InterpretStateC eff s m [a]
some :: InterpretStateC eff s m a -> InterpretStateC eff s m [a]
$csome :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
(Alternative m, Monad m) =>
InterpretStateC eff s m a -> InterpretStateC eff s m [a]
<|> :: InterpretStateC eff s m a
-> InterpretStateC eff s m a -> InterpretStateC eff s m a
$c<|> :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
(Alternative m, Monad m) =>
InterpretStateC eff s m a
-> InterpretStateC eff s m a -> InterpretStateC eff s m a
empty :: InterpretStateC eff s m a
$cempty :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
(Alternative m, Monad m) =>
InterpretStateC eff s m a
$cp1Alternative :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *).
(Alternative m, Monad m) =>
Applicative (InterpretStateC eff s m)
Alternative, Functor (InterpretStateC eff s m)
a -> InterpretStateC eff s m a
Functor (InterpretStateC eff s m) =>
(forall a. a -> InterpretStateC eff s m a)
-> (forall a b.
    InterpretStateC eff s m (a -> b)
    -> InterpretStateC eff s m a -> InterpretStateC eff s m b)
-> (forall a b c.
    (a -> b -> c)
    -> InterpretStateC eff s m a
    -> InterpretStateC eff s m b
    -> InterpretStateC eff s m c)
-> (forall a b.
    InterpretStateC eff s m a
    -> InterpretStateC eff s m b -> InterpretStateC eff s m b)
-> (forall a b.
    InterpretStateC eff s m a
    -> InterpretStateC eff s m b -> InterpretStateC eff s m a)
-> Applicative (InterpretStateC eff s m)
InterpretStateC eff s m a
-> InterpretStateC eff s m b -> InterpretStateC eff s m b
InterpretStateC eff s m a
-> InterpretStateC eff s m b -> InterpretStateC eff s m a
InterpretStateC eff s m (a -> b)
-> InterpretStateC eff s m a -> InterpretStateC eff s m b
(a -> b -> c)
-> InterpretStateC eff s m a
-> InterpretStateC eff s m b
-> InterpretStateC eff s m c
forall a. a -> InterpretStateC eff s m a
forall a b.
InterpretStateC eff s m a
-> InterpretStateC eff s m b -> InterpretStateC eff s m a
forall a b.
InterpretStateC eff s m a
-> InterpretStateC eff s m b -> InterpretStateC eff s m b
forall a b.
InterpretStateC eff s m (a -> b)
-> InterpretStateC eff s m a -> InterpretStateC eff s m b
forall a b c.
(a -> b -> c)
-> InterpretStateC eff s m a
-> InterpretStateC eff s m b
-> InterpretStateC eff s m c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *).
Monad m =>
Functor (InterpretStateC eff s m)
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
Monad m =>
a -> InterpretStateC eff s m a
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a b.
Monad m =>
InterpretStateC eff s m a
-> InterpretStateC eff s m b -> InterpretStateC eff s m a
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a b.
Monad m =>
InterpretStateC eff s m a
-> InterpretStateC eff s m b -> InterpretStateC eff s m b
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a b.
Monad m =>
InterpretStateC eff s m (a -> b)
-> InterpretStateC eff s m a -> InterpretStateC eff s m b
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a b c.
Monad m =>
(a -> b -> c)
-> InterpretStateC eff s m a
-> InterpretStateC eff s m b
-> InterpretStateC eff s m c
<* :: InterpretStateC eff s m a
-> InterpretStateC eff s m b -> InterpretStateC eff s m a
$c<* :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a b.
Monad m =>
InterpretStateC eff s m a
-> InterpretStateC eff s m b -> InterpretStateC eff s m a
*> :: InterpretStateC eff s m a
-> InterpretStateC eff s m b -> InterpretStateC eff s m b
$c*> :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a b.
Monad m =>
InterpretStateC eff s m a
-> InterpretStateC eff s m b -> InterpretStateC eff s m b
liftA2 :: (a -> b -> c)
-> InterpretStateC eff s m a
-> InterpretStateC eff s m b
-> InterpretStateC eff s m c
$cliftA2 :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a b c.
Monad m =>
(a -> b -> c)
-> InterpretStateC eff s m a
-> InterpretStateC eff s m b
-> InterpretStateC eff s m c
<*> :: InterpretStateC eff s m (a -> b)
-> InterpretStateC eff s m a -> InterpretStateC eff s m b
$c<*> :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a b.
Monad m =>
InterpretStateC eff s m (a -> b)
-> InterpretStateC eff s m a -> InterpretStateC eff s m b
pure :: a -> InterpretStateC eff s m a
$cpure :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
Monad m =>
a -> InterpretStateC eff s m a
$cp1Applicative :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *).
Monad m =>
Functor (InterpretStateC eff s m)
Applicative, a -> InterpretStateC eff s m b -> InterpretStateC eff s m a
(a -> b) -> InterpretStateC eff s m a -> InterpretStateC eff s m b
(forall a b.
 (a -> b) -> InterpretStateC eff s m a -> InterpretStateC eff s m b)
-> (forall a b.
    a -> InterpretStateC eff s m b -> InterpretStateC eff s m a)
-> Functor (InterpretStateC eff s m)
forall a b.
a -> InterpretStateC eff s m b -> InterpretStateC eff s m a
forall a b.
(a -> b) -> InterpretStateC eff s m a -> InterpretStateC eff s m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a b.
Functor m =>
a -> InterpretStateC eff s m b -> InterpretStateC eff s m a
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a b.
Functor m =>
(a -> b) -> InterpretStateC eff s m a -> InterpretStateC eff s m b
<$ :: a -> InterpretStateC eff s m b -> InterpretStateC eff s m a
$c<$ :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a b.
Functor m =>
a -> InterpretStateC eff s m b -> InterpretStateC eff s m a
fmap :: (a -> b) -> InterpretStateC eff s m a -> InterpretStateC eff s m b
$cfmap :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a b.
Functor m =>
(a -> b) -> InterpretStateC eff s m a -> InterpretStateC eff s m b
Functor, Applicative (InterpretStateC eff s m)
a -> InterpretStateC eff s m a
Applicative (InterpretStateC eff s m) =>
(forall a b.
 InterpretStateC eff s m a
 -> (a -> InterpretStateC eff s m b) -> InterpretStateC eff s m b)
-> (forall a b.
    InterpretStateC eff s m a
    -> InterpretStateC eff s m b -> InterpretStateC eff s m b)
-> (forall a. a -> InterpretStateC eff s m a)
-> Monad (InterpretStateC eff s m)
InterpretStateC eff s m a
-> (a -> InterpretStateC eff s m b) -> InterpretStateC eff s m b
InterpretStateC eff s m a
-> InterpretStateC eff s m b -> InterpretStateC eff s m b
forall a. a -> InterpretStateC eff s m a
forall a b.
InterpretStateC eff s m a
-> InterpretStateC eff s m b -> InterpretStateC eff s m b
forall a b.
InterpretStateC eff s m a
-> (a -> InterpretStateC eff s m b) -> InterpretStateC eff s m b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *).
Monad m =>
Applicative (InterpretStateC eff s m)
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
Monad m =>
a -> InterpretStateC eff s m a
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a b.
Monad m =>
InterpretStateC eff s m a
-> InterpretStateC eff s m b -> InterpretStateC eff s m b
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a b.
Monad m =>
InterpretStateC eff s m a
-> (a -> InterpretStateC eff s m b) -> InterpretStateC eff s m b
return :: a -> InterpretStateC eff s m a
$creturn :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
Monad m =>
a -> InterpretStateC eff s m a
>> :: InterpretStateC eff s m a
-> InterpretStateC eff s m b -> InterpretStateC eff s m b
$c>> :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a b.
Monad m =>
InterpretStateC eff s m a
-> InterpretStateC eff s m b -> InterpretStateC eff s m b
>>= :: InterpretStateC eff s m a
-> (a -> InterpretStateC eff s m b) -> InterpretStateC eff s m b
$c>>= :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a b.
Monad m =>
InterpretStateC eff s m a
-> (a -> InterpretStateC eff s m b) -> InterpretStateC eff s m b
$cp1Monad :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *).
Monad m =>
Applicative (InterpretStateC eff s m)
Monad, Monad (InterpretStateC eff s m)
Monad (InterpretStateC eff s m) =>
(forall a. String -> InterpretStateC eff s m a)
-> MonadFail (InterpretStateC eff s m)
String -> InterpretStateC eff s m a
forall a. String -> InterpretStateC eff s m a
forall (m :: * -> *).
Monad m =>
(forall a. String -> m a) -> MonadFail m
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *).
MonadFail m =>
Monad (InterpretStateC eff s m)
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
MonadFail m =>
String -> InterpretStateC eff s m a
fail :: String -> InterpretStateC eff s m a
$cfail :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
MonadFail m =>
String -> InterpretStateC eff s m a
$cp1MonadFail :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *).
MonadFail m =>
Monad (InterpretStateC eff s m)
Fail.MonadFail, Monad (InterpretStateC eff s m)
Monad (InterpretStateC eff s m) =>
(forall a.
 (a -> InterpretStateC eff s m a) -> InterpretStateC eff s m a)
-> MonadFix (InterpretStateC eff s m)
(a -> InterpretStateC eff s m a) -> InterpretStateC eff s m a
forall a.
(a -> InterpretStateC eff s m a) -> InterpretStateC eff s m a
forall (m :: * -> *).
Monad m =>
(forall a. (a -> m a) -> m a) -> MonadFix m
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *).
MonadFix m =>
Monad (InterpretStateC eff s m)
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
MonadFix m =>
(a -> InterpretStateC eff s m a) -> InterpretStateC eff s m a
mfix :: (a -> InterpretStateC eff s m a) -> InterpretStateC eff s m a
$cmfix :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
MonadFix m =>
(a -> InterpretStateC eff s m a) -> InterpretStateC eff s m a
$cp1MonadFix :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *).
MonadFix m =>
Monad (InterpretStateC eff s m)
MonadFix, Monad (InterpretStateC eff s m)
Monad (InterpretStateC eff s m) =>
(forall a. IO a -> InterpretStateC eff s m a)
-> MonadIO (InterpretStateC eff s m)
IO a -> InterpretStateC eff s m a
forall a. IO a -> InterpretStateC eff s m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> MonadIO m
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *).
MonadIO m =>
Monad (InterpretStateC eff s m)
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
MonadIO m =>
IO a -> InterpretStateC eff s m a
liftIO :: IO a -> InterpretStateC eff s m a
$cliftIO :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
MonadIO m =>
IO a -> InterpretStateC eff s m a
$cp1MonadIO :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *).
MonadIO m =>
Monad (InterpretStateC eff s m)
MonadIO, Monad (InterpretStateC eff s m)
Alternative (InterpretStateC eff s m)
InterpretStateC eff s m a
(Alternative (InterpretStateC eff s m),
 Monad (InterpretStateC eff s m)) =>
(forall a. InterpretStateC eff s m a)
-> (forall a.
    InterpretStateC eff s m a
    -> InterpretStateC eff s m a -> InterpretStateC eff s m a)
-> MonadPlus (InterpretStateC eff s m)
InterpretStateC eff s m a
-> InterpretStateC eff s m a -> InterpretStateC eff s m a
forall a. InterpretStateC eff s m a
forall a.
InterpretStateC eff s m a
-> InterpretStateC eff s m a -> InterpretStateC eff s m a
forall (m :: * -> *).
(Alternative m, Monad m) =>
(forall a. m a) -> (forall a. m a -> m a -> m a) -> MonadPlus m
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *).
(Alternative m, Monad m) =>
Monad (InterpretStateC eff s m)
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *).
(Alternative m, Monad m) =>
Alternative (InterpretStateC eff s m)
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
(Alternative m, Monad m) =>
InterpretStateC eff s m a
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
(Alternative m, Monad m) =>
InterpretStateC eff s m a
-> InterpretStateC eff s m a -> InterpretStateC eff s m a
mplus :: InterpretStateC eff s m a
-> InterpretStateC eff s m a -> InterpretStateC eff s m a
$cmplus :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
(Alternative m, Monad m) =>
InterpretStateC eff s m a
-> InterpretStateC eff s m a -> InterpretStateC eff s m a
mzero :: InterpretStateC eff s m a
$cmzero :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
(Alternative m, Monad m) =>
InterpretStateC eff s m a
$cp2MonadPlus :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *).
(Alternative m, Monad m) =>
Monad (InterpretStateC eff s m)
$cp1MonadPlus :: forall (eff :: (* -> *) -> * -> *) s (m :: * -> *).
(Alternative m, Monad m) =>
Alternative (InterpretStateC eff s m)
MonadPlus)

instance MonadTrans (InterpretStateC eff s) where
  lift :: m a -> InterpretStateC eff s m a
lift = ReaderC (HandlerState eff s m) (StateC s m) a
-> InterpretStateC eff s m a
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
ReaderC (HandlerState eff s m) (StateC s m) a
-> InterpretStateC eff s m a
InterpretStateC (ReaderC (HandlerState eff s m) (StateC s m) a
 -> InterpretStateC eff s m a)
-> (m a -> ReaderC (HandlerState eff s m) (StateC s m) a)
-> m a
-> InterpretStateC eff s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StateC s m a -> ReaderC (HandlerState eff s m) (StateC s m) a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (StateC s m a -> ReaderC (HandlerState eff s m) (StateC s m) a)
-> (m a -> StateC s m a)
-> m a
-> ReaderC (HandlerState eff s m) (StateC s m) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> StateC s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift
  {-# INLINE lift #-}

newtype HandlerState eff s m = HandlerState (forall x . eff (StateC s m) x -> StateC s m x)

runHandlerState :: (HFunctor eff, Functor m) => HandlerState eff s m -> eff (InterpretStateC eff s m) a -> StateC s m a
runHandlerState :: HandlerState eff s m
-> eff (InterpretStateC eff s m) a -> StateC s m a
runHandlerState h :: HandlerState eff s m
h@(HandlerState handler :: forall x. eff (StateC s m) x -> StateC s m x
handler) = eff (StateC s m) a -> StateC s m a
forall x. eff (StateC s m) x -> StateC s m x
handler (eff (StateC s m) a -> StateC s m a)
-> (eff (InterpretStateC eff s m) a -> eff (StateC s m) a)
-> eff (InterpretStateC eff s m) a
-> StateC s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall x. InterpretStateC eff s m x -> StateC s m x)
-> eff (InterpretStateC eff s m) a -> eff (StateC s m) a
forall (h :: (* -> *) -> * -> *) (m :: * -> *) (n :: * -> *) a.
(HFunctor h, Functor m) =>
(forall x. m x -> n x) -> h m a -> h n a
hmap (HandlerState eff s m
-> ReaderC (HandlerState eff s m) (StateC s m) x -> StateC s m x
forall r (m :: * -> *) a. r -> ReaderC r m a -> m a
runReader HandlerState eff s m
h (ReaderC (HandlerState eff s m) (StateC s m) x -> StateC s m x)
-> (InterpretStateC eff s m x
    -> ReaderC (HandlerState eff s m) (StateC s m) x)
-> InterpretStateC eff s m x
-> StateC s m x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InterpretStateC eff s m x
-> ReaderC (HandlerState eff s m) (StateC s m) x
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
InterpretStateC eff s m a
-> ReaderC (HandlerState eff s m) (StateC s m) a
runInterpretStateC)

instance (HFunctor eff, Carrier sig m, Effect sig) => Carrier (eff :+: sig) (InterpretStateC eff s m) where
  eff :: (:+:) eff sig (InterpretStateC eff s m) a
-> InterpretStateC eff s m a
eff (L op :: eff (InterpretStateC eff s m) a
op) = do
    HandlerState eff s m
handler <- ReaderC (HandlerState eff s m) (StateC s m) (HandlerState eff s m)
-> InterpretStateC eff s m (HandlerState eff s m)
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
ReaderC (HandlerState eff s m) (StateC s m) a
-> InterpretStateC eff s m a
InterpretStateC ReaderC (HandlerState eff s m) (StateC s m) (HandlerState eff s m)
forall r (sig :: (* -> *) -> * -> *) (m :: * -> *).
(Member (Reader r) sig, Carrier sig m) =>
m r
ask
    ReaderC (HandlerState eff s m) (StateC s m) a
-> InterpretStateC eff s m a
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
ReaderC (HandlerState eff s m) (StateC s m) a
-> InterpretStateC eff s m a
InterpretStateC (StateC s m a -> ReaderC (HandlerState eff s m) (StateC s m) a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (HandlerState eff s m
-> eff (InterpretStateC eff s m) a -> StateC s m a
forall (eff :: (* -> *) -> * -> *) (m :: * -> *) s a.
(HFunctor eff, Functor m) =>
HandlerState eff s m
-> eff (InterpretStateC eff s m) a -> StateC s m a
runHandlerState HandlerState eff s m
handler eff (InterpretStateC eff s m) a
op))
  eff (R other :: sig (InterpretStateC eff s m) a
other) = ReaderC (HandlerState eff s m) (StateC s m) a
-> InterpretStateC eff s m a
forall (eff :: (* -> *) -> * -> *) s (m :: * -> *) a.
ReaderC (HandlerState eff s m) (StateC s m) a
-> InterpretStateC eff s m a
InterpretStateC ((:+:)
  (Reader (HandlerState eff s m))
  (State s :+: sig)
  (ReaderC (HandlerState eff s m) (StateC s m))
  a
-> ReaderC (HandlerState eff s m) (StateC s m) a
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Carrier sig m =>
sig m a -> m a
eff ((:+:) (State s) sig (ReaderC (HandlerState eff s m) (StateC s m)) a
-> (:+:)
     (Reader (HandlerState eff s m))
     (State s :+: sig)
     (ReaderC (HandlerState eff s m) (StateC s m))
     a
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
g m k -> (:+:) f g m k
R (sig (ReaderC (HandlerState eff s m) (StateC s m)) a
-> (:+:)
     (State s) sig (ReaderC (HandlerState eff s m) (StateC s m)) a
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
g m k -> (:+:) f g m k
R (sig (InterpretStateC eff s m) a
-> sig (ReaderC (HandlerState eff s m) (StateC s m)) a
forall (sig :: (* -> *) -> * -> *) (f :: * -> *) (g :: * -> *) a.
(HFunctor sig, Functor f, Coercible f g) =>
sig f a -> sig g a
handleCoercible sig (InterpretStateC eff s m) a
other))))
  {-# INLINE eff #-}


-- $setup
-- >>> import Test.QuickCheck
-- >>> import Control.Effect.Pure
-- >>> import Control.Effect.State