Replies: 8 comments
-
Koka supports multiple instances of the same effect in two ways: masking, and named handlers (WIP). Masking allows you to skip the innermost handler for that corresponding effect, so that the operation is handled by the second to innermost handler, e.g.,
A more concise way is to use named handlers, where handlers are given named so that operations can be performed directly on a specific handler. There are some samples regarding named handlers.
|
Beta Was this translation helpful? Give feedback.
-
Hi Dan, good to see you here :-) Just to add to Ningning's excellent answer, named handlers is still active research (and mask is a bit cumbersome). However, I feel that in practice we should not use either for the state example you gave: I think when possible it is best to create specific effect instances for the actual domain specific use case. For example, when I write a type inferencer, I may need multiple states, like a unique counter to generate unique names, and a current substitution. Now, instead of using two generic
for example. The intended use case for named handlers is when you need dynamic "resources", e.g. say a number of files or network connections. Although, even in that case we may get away with a single effect handler that hands out "handles" to access individual items. |
Beta Was this translation helpful? Give feedback.
-
Thanks Ningning and Daan, this is quite neat! I'll close since my question has been answered. |
Beta Was this translation helpful? Give feedback.
-
Would it be fair to compare "effect masking" to
Nice. Named handlers seem more flexible and easier-to-use, it reminds me of named typeclass instances. |
Beta Was this translation helpful? Give feedback.
-
That's an astute high-level design observation! I guess in a language like Koka with first-class effects, it makes sense to make one-off effects for a specific purpose (for clarity and ease of understanding). In languages with ADTs (first-class datatypes), this is analogous to the design principle of creating custom ADTs instead of using existing, less-informative ones like |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I dislike losing these interesting issues with nice responses by closing them... I think I will add discussions to the koka github so it is easier to discuss things like this (as with the partially applied type aliases topic) |
Beta Was this translation helpful? Give feedback.
-
Thanks for sharing! In addition to "boolean blindness", I think there's also the unfortunate consequence of "boolean information narrowing": we discard a lot of information when we narrow an information-rich ADT to |
Beta Was this translation helpful? Give feedback.
-
Koka has effect types in function types. Example:
Can Koka support distinct
state<int>
effects in the same function type, each representing a separate heap reference? Use cases include representing programs operating on multiple mutable references at once:get<state1>()
andget<state2>()
. Without loss of generality, does this feature extend to other effect types too?The theory behind effect handlers (multi-prompt delimited continuations) seems to allow this flexibility? I wonder if that is indeed supportable, and if it is implemented in Koka.
Beta Was this translation helpful? Give feedback.
All reactions