-
Notifications
You must be signed in to change notification settings - Fork 1
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
Consider adding a _different_ effect that holds an implicit Scope
#10
Comments
Hello @michaelpj, That sounds good to me. However, while this should fix #6, I'm concerned about the increased complexity. For example:
-- | Provide a callback function to run an action within the current `Scope`.
withCurrentScope ::
Scoped :> es =>
((forall es' a. Scoped :> es' => Eff es' a -> Eff es' a) -> Eff es b) ->
Eff es b
withCurrentScope f = do
rep <- getStaticRep @Scoped
f (localStaticRep (const rep))
I wouldn't mind integrating this new design to see how it works in practice, though I have to say that I'm not using this library. I was hoping to pull it in Butler, but I'm still debating the complexity cost of an effect system. So I'd love to get the opinion of @mmhat and @mitchellwrosen on this new design. Thanks! |
For the record, |
I think they do. What I'm proposing is really just a synonym for
I'm not sure I'm understanding the use case, but if you want to have two
Awkward. Arguably you in fact only need STM in But I do agree this would be nicer with a STM effect.
I think there are interesting cases here. One is if you have some code that will run in a multi-threaded scenario, but is itself single-threaded. Such code often reads and writes |
Correct, given |
I'm afraid I don't have too much to add to the discussion here beyond the scattered thoughts in #6 and in a few discussions, but regarding this:
I will note that "Running a structured concurrency scope" isn't captured in the type system in any of these variants as far as I understand: it's just an IO action. And remember: a scopes form a tree; it's not just zero or one. So the type system ought not to prevent a thread from creating a scope just because it itself has been created in a scope, or something like that. (Hand-waving a bit here because I'm not that familiar with this effect system). I can certainly imagine Cheers! |
Thank you for taking the time to provide your feedback. I really appreciate it! I think @michaelpj meant that Thank you for introducing labeled effects, that looks useful, though I'm not sure how I would use that in butler. My use-case is for a helper function (code) to create a kill-able 'Process', using the Additionally, I’m cautious about the debugging experience. I had to take this helper apart to reproduce awkward-squad/ki#19 , and having an explicit scope helped the investigation. That being said, I’m open to being persuaded otherwise, but |
I hadn't thought about that, but I guess it is somewhat true: if you have only
Our use case is pretty much the one I describe here: awkward-squad/ki#35 To be honest, my main motivation is the abstract one I gave in the original post about how we track effect handles. Scopes look like effect handles and so I feel like I should be putting them in constraints! But it's not exactly a big deal. |
In #1 and #6 we went back and forth on whether or not
StructuredConcurrency
should hold aScope
.I wonder whether we might want to just have a different effect (straw name:
Scoped
) that holds aScope
. That is:StructuredConcurrency
tells us that the computation may create structured concurrency scopesScoped
tells us that a computation is actually running in a structured concurrency scope.This isn't an unusual pattern, it's a bit like having one effect that says "you can access the database" and one effect that says "you are in a transaction".
Concretely, this might look like this:
Why do this? Well, it seems to me that
Scope
is a handle for a local effect, namely spawning threads into the scope you created. We have a bit of a split in the effect-systems community about whether we like explicit handles (bluefin
-style) or constraints (effectful
-style). Sinceeffectful
tends to go for managing effect handles using constraints, perhaps it is more idiomatic to do that forScope
s.What about the worry in #6 ? My take on that is that the suspicious thing is taking a
Scope
as an argument to a top-level. The only change withScoped
would be that havingScoped
as a constraint on a top-level function would be a bit suspicious. Perhaps it makes it seem more natural to inheritScoped
constraints, and that's bad? But that seems like an education problem, much like it seems natural to pass aroundScope
s, but maybe that's bad.Plus, because
Scoped
is a separate effect, you can still run everything in local scopes perfectly well. And we can provide both styles without them interfering with each other.The text was updated successfully, but these errors were encountered: