Verified Commit 622304b2 authored by Justin Andresen's avatar Justin Andresen
Browse files

Avoid internal combinators

parent 7b38cd34
......@@ -8,22 +8,34 @@
module MyHandlers where
import Polysemy
import Polysemy.Internal.Combinators
import Polysemy.State
import MyEffects
-- It is not possible to write stateful effect handlers in Polysemy
-- without importing internal modules. Handling of the state has to
-- be reinterpreted in terms of the built-in state effect.
runMyState :: s -> Sem (MyState s ': r) a -> Sem r (s, a)
runMyState = stateful $ \case
runMyState initialState = runState initialState . reinterpret \case
MyGet -> get
MyPut s' -> put s'
{-
-- Alternative solution with internal combinator.
import Polysemy.Internal.Combinators
runMyState = stateful \case
MyGet -> \s -> return (s, s)
MyPut s' -> \_ -> return (s', ())
-}
logMyState :: (Members '[MyState s, MyLog] r, Show s) => Sem r a -> Sem r a
logMyState = intercept $ \case
logMyState = intercept \case
MyGet -> myGet
MyPut s' -> do
myLog s'
myPut s'
printLog :: Member (Embed IO) r => Sem (MyLog ': r) a -> Sem r a
printLog = interpret $ \case
printLog = interpret \case
MyLog msg -> embed $ putStrLn ("Info: " ++ show msg)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment