-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IORef-based carrier for the Accum effect. #430
Conversation
No, I see what you mean by "slice." Mea culpa. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of notes, no blockers. Nice one!
Add w' -> liftIO (modifyIORef' ref (S.<> w')) | ||
Look -> liftIO (readIORef ref) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could factor out the liftIO
, if you really cared to.
instance (Algebra sig m, S.Semigroup w, MonadIO m) => Algebra (Accum w :+: sig) (AccumC w m) where | ||
alg hdl sig ctx = case sig of | ||
L accum -> do | ||
ref <- AccumC (ask @(IORef w)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes I prefer to do this sort of thing by constructing the ReaderC
directly instead of ask
ing with a type application, e.g.:
case sig of
L accum -> AccumC $ ReaderC $ \ ref -> do
…
I'm not fussed either way.
There exists no
IORef
-based carrier for theWriter
effect, as in an impure context there is no way to slice a section of the computation out (forlisten
andpass
). However, there is a very straightforward one for theAccum
effect. This defines such a carrier.