Replies: 2 comments 3 replies
-
This is definitely possible right now. You just have to explicitly mask the first exception in the row to match types for the second one.
This is partially due to the fact that for polymorphic exceptions you cannot assume one ordering or the other. Should f1 use the first or second ?
Personally I believe that we could probably auto-insert masks for duplicate effect labels when they are fully concrete. But the inference would be more complicated, in addition to the fact that the ordering of handlers on the stack is made more explicit and less flexible. I would suggest creating different effect types instead.
This is in general more composable, at least the way Koka's effect inference works. There are other effect systems that use sets rather than rows. As far as the builtin exception type you can extend it using:
Or something like that. As a side note, I'd love for open types to group constructors as a row, and then let you add / remove / specify which constructors, but I don't think this completely solves this problem since the open type (exception-info) is embedded into the exception type. |
Beta Was this translation helpful? Give feedback.
-
As an aside, open types are described under Extensible Types at https://koka-community.github.io/koka-docs/koka-docs.kk.html#sec-type-definitions. |
Beta Was this translation helpful? Give feedback.
-
Effects generalize exceptions, but I'm not sure how to make user code that throws exceptions compose.
Consider:
The standard library seems to work around this with an "open type":
koka/lib/std/core/exn.kk
Lines 35 to 42 in e285887
I'm not sure what an open type is as I can't find any documentation on it, but regardless, it's clear that with this type a function with the standard library
exn
effect can throw anything value in this type, so the handlers also need to handle everything, which is also not ideal.I think ideally, the type system should allow for:
exn<...here...>
).exception1
, it should be allowed to be passed as a function that throwsexception1
andexception2
. (e.g. as a callback)At least the first two seems to be what row types do in the effect system, but they're not available in the user types as far as I can see?
Is this kind of thing possible right now? Are there any plans to support this use case?
Beta Was this translation helpful? Give feedback.
All reactions