Help with Event Effect #156
-
i am trying to create a event effect, basically it would have 2 operations registerHandler which would add the given action to a list and raiseEvent which would call all actions with the given argument so if using a dynamic effect we could have the following data Event e m a where
RegisterHandler :: (e -> m ()) -> Event e m ()
RaiseEvent :: e -> Event e m ()
registerHandler ::Event e :> es => (e -> Eff es ()) -> Eff es ()
registerHandler = send . RegisterHandler
raiseEvent :: Event e :> es => e -> Eff es ()
raiseEvent = send . RaiseEvent
type instance DispatchOf (Event e) = 'Dynamic the problem comes when we try to implement it runEvent ::forall e es a. Eff (Event e ': es) a -> Eff es a
runEvent = reinterpret (evalState ([]::[e -> Eff es ()])) $ \env -> \case
(RegisterHandler act) -> localUnlift env (ConcUnlift Persistent Unlimited) $ \unlift -> modify @([e -> Eff es ()]) ((unlift . act) :) however this fails as (unlift . act) outputs a e -> Eff (State [e -> Eff es ()] ': es) () and not the wanted e -> Eff es () |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You need runEvent ::forall e es a. Eff (Event e ': es) a -> Eff es a
runEvent = reinterpret (evalState ([]::[e -> Eff es ()])) $ \env -> \case
(RegisterHandler act) -> raiseWith SeqUnlift $ \lower -> do
localUnlift env (ConcUnlift Persistent Unlimited) $ \unlift -> lower $ do
modify ((unlift . act) :) |
Beta Was this translation helpful? Give feedback.
You need
raiseWith
: