-
Notifications
You must be signed in to change notification settings - Fork 28
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
Utility functions for handling effects #231
Conversation
Well, actually maybe |
I think your comment is a good suggestion. Then we don't really introduce any new terms. So I'm +1 on |
Yeah, that would have been what I would have gone for. |
203f022
to
f03933f
Compare
f03933f
to
cb97e86
Compare
Ok, I added all possible variants, it should be good to go. |
-> EffectHandler e handlerEs | ||
-- ^ The effect handler. | ||
-> Eff es b | ||
reinterpretWith runHandlerEs m handler = reinterpret runHandlerEs handler m |
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.
I'm slightly sceptical of all the variants. With this one I think it's quite likely that runHandlerEs
is also quite large, so is it going to make sense to privilege handler
as the postfix one? I'm unsure, which makes me wonder if we should omit it for now.
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.
In my experience runHandlerEs
is usually a single internal runner like runReader
or runState
(maybe both?). In the event that it's an additional setup, like
blah = reinterpret run $ \case
...
where
run m = do
x <- setup1
y <- setup2
runState x $ runReader y m
reinterpretWith
should actually help with this:
blah m = do
x <- setup1
y <- setup2
reinterpretWith (runState x . runReader y) m $ \case
...
On the other hand, the handler is almost always multiline, so if you can't partially apply reinterpret
, you need to bind the handler separately.
To not look very far, the code from #229 would benefit from reinterpretWith
.
Am I missing something? 🙂
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.
No, that's convincing!
-> EffectHandler e es | ||
-- ^ The effect handler. | ||
-> Eff es a | ||
interposeWith m handler = interpose handler m |
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.
👍
-> EffectHandler e handlerEs | ||
-- ^ The effect handler. | ||
-> Eff es b | ||
imposeWith runHandlerEs m handler = impose runHandlerEs handler m |
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.
Same comment as about reinterpretWith
Thanks! |
Supersedes #230.
@michaelpj @ocharles does that work for you?
I decided to go with
handleWith
instead ofinterpretWith
since the nameinterpretWith
is too close tointerpret
and might be confusing.Still reads nicely:
and won't clash with
Control.Monad.Catch
.