-
Notifications
You must be signed in to change notification settings - Fork 151
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
Polymorphic effect cannot have seperate handlers #241
Comments
The example was from https://www.oxinabox.net/2020/02/09/whycompositionaljulia.html |
Thanks for the example! I will try to read/see the talk that is linked so I can better understand the goals. (I will try to answer but perhaps I miss some design goals that are not apparent). So, effect inference is not broken :-) but it behaves different than you expected. When doing inference on the effect "rows" only the name of the effect is matched ( In the example, the first There are (at least) two ways around this:
Hope this helps! (ps: just to be complete, here is the program with masking: (but try to avoid mask for this)
|
I'm trying to have type classes that only work in a scope. The imagined use case is that library A defines the effect only has |
@locriacyber Hi, the github discussions tab is probably a better place for this question. Right now koka has a gitter chatroom, and since some time this is compatible with matrix. It is pretty inactive, but you can join it here. |
Hi @locriacyber, polymorphic effects not working this way is an intended part of koka. It would be extremely difficult and slow to add this. Because polymorphic effects would require the type of the arguments to be known at runtime. This means runtime types would also need to be added, and that only slows things down and makes them more complicated. |
I don't think runtime types are needed. Each The problem is that now handler of |
Yes, in this example it is indeed clear what side effect handler should be called. But these handlers could be completely unkown and/or different for the same function. And in that case you need the runtime type to call the correct function. |
Can you give an example? |
The restriction is indeed fundamental (and intended). The reasons are three-fold:
The third one means that when we have an effect row with different effects "labels", like Moreover, we can have (polymorpic) type parameters to effect "labels", like Hope this helps :-) The references may contain more examples. Here is a short example that shows that we cannot be rely on type parameters to infer which handler should be invoked (as in your original example):
Here we set up three handlers, so the inferred effect context for You may argue that we could infer this automatically in this case, but consider writing [1] Ningning Xie and Daan Leijen. “ Generalized Evidence Passing for Effect Handlers” In The 26th ACM SIGPLAN International Conference on Functional Programming (ICFP), August 2021. [2] Daan Leijen, "Extensible records with scoped labels" pdf |
(I think Koka has implicit What's the use case for this type of effect handler?
In practice, |
@daanx can you move this issue to Github discussion? |
The following code should work in theory, since
raise_baby
is polymorphic. But currently, koka only accepts the one handler for polymorphic effects.The text was updated successfully, but these errors were encountered: