Skip to content
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

Merged
merged 6 commits into from
Jul 12, 2022
Merged

Add IORef-based carrier for the Accum effect. #430

merged 6 commits into from
Jul 12, 2022

Conversation

patrickt
Copy link
Collaborator

@patrickt patrickt commented Jul 5, 2022

There exists no IORef-based carrier for the Writer effect, as in an impure context there is no way to slice a section of the computation out (for listen and pass). However, there is a very straightforward one for the Accum effect. This defines such a carrier.

@patrickt patrickt requested a review from robrix July 11, 2022 14:11
@robrix
Copy link
Contributor

robrix commented Jul 12, 2022

@patrickt: It seems like we should be able to get Writer by running the action, reading from the IORef, and returning both, no?

No, I see what you mean by "slice." Mea culpa.

Copy link
Contributor

@robrix robrix left a 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!

Comment on lines +96 to +97
Add w' -> liftIO (modifyIORef' ref (S.<> w'))
Look -> liftIO (readIORef ref)
Copy link
Contributor

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))
Copy link
Contributor

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 asking with a type application, e.g.:

case sig of
  L accum -> AccumC $ ReaderC $ \ ref -> do
    

I'm not fussed either way.

@patrickt patrickt merged commit ba8c759 into main Jul 12, 2022
@patrickt patrickt deleted the impure-writer branch July 12, 2022 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants