-
Notifications
You must be signed in to change notification settings - Fork 18
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
Dynamic handlers #145
Comments
After discussion with @forell, we agreed on the approach to dynamic handlers. In general, dynamic handlers are just syntactic sugar to parametrized version of shift₀/reset₀ control operators. To be more specific, we should introduce the following changes and features. (Suggested concrete syntax is just a proposition, and I'm open to other suggestions.) Label typeLabel type contains a telescope of named parameters that describes types and values attached to the delimiter. This additional parameters allows to use encoding similar to the one proposed by Piróg et al., but simplified (where encoding of state monad is changed to the reader). For instance, the ecoding of backtracking effect will use the following label type, where
The regular user should never see such a type due to syntactic sugar described later in this post. Control effectsWe can reuse
However, the regular user should never use this construct (for dynamic stuff) directly. Syntactic sugar for dynamic signaturesWe can write signatures of dynamic effects in the following way.
Similarly to records, it can be desugared into ADT with a single constructor (named
Dynamic handlersDynamic handler is just a reset₀ control operator parametrized by named things attached to the label type. For instance, for the backtracking handler we could write the following.
Of course, we can omit DT and DE parameters, as they can be infered. But we can provide them if we want.
The parameter Generating fresh labelsFresh labels can be generated by
I can imagine, a more general dynamic signatures, that contains additional fields that are constant to the effect instance, but not to particular handler. These parameters could be passed at label allocation:
If we use this approach, then the meaning of |
Lexical effect handlers are nice and disciplined, but make some things, like lightweight threads, difficult to express. Fram used to allow first-class labels to be generated and then used by multiple
handle
expressions, but that functionality had to be removed when thereturn
andfinally
clauses were moved fromhandle
to first-class handler creation withhandler
in bc226d0, since the type and effect of the delimiter are no longer visible in the handler type.Some form of dynamic handlers should be implemented in Fram. Part of the necessary work has already been done in c237db2, allowing convenient encoding of dynamic handlers in terms of shift₀ and reset₀, but nothing is exposed to the programmer yet. The old tests and example for first-class labels that were removed in bc226d0 should potentially be reintroduced in some way.
The text was updated successfully, but these errors were encountered: