Effect Operations, Handlers, and Resumption

Separate a request made by a computation from the interpretation supplied by a handler and trace what resuming means.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. An operation can suspend at a defined interface
  2. The resumption policy changes the semantics

An operation can suspend at a defined interface

Imagine evaluation of \(2+\operatorname{ask}()\), where ask requests an integer from a surrounding environment. The request supplies an operation name and argument, plus a resumption representing the context waiting for the answer. A handler choosing answer \(5\) resumes that context and obtains \(7\). Another handler can interpret the same request through a different environment while retaining the arithmetic computation.

The resumption policy changes the semantics

A handler can resume once, return without resuming, or, in a language allowing it, resume several times with different answers. Repeated resumption can repeat effects in the suspended continuation, so ownership and resource behavior depend on the rules for use. Continuation-passing style represents a similar waiting context explicitly. Advanced algebraic effects develops calculus rules and typing for these behaviors.[1][2]

References

  1. Shriram Krishnamurthi, Programming Languages: Application and Interpretation ↩
  2. Robert Nystrom, Crafting Interpreters ↩