Concurrent System Programming with Effect Handlers
read more
Citations
Structured asynchrony with algebraic effects
Effekt: Capability-passing style for type- and effect-safe, extensible effect handlers in Scala
Effect handlers, evidently
Effect handlers via generalised continuations
Compiling effect handlers in capability-passing style
References
Notions of computation and monads
Concurrent Programming in Erlang
The essence of functional programming
Formal Methods for Components and Objects
Revised Report on the Algorithmic Language Scheme
Related Papers (5)
Frequently Asked Questions (16)
Q2. What is the primary motivation for adding effect handlers in Multicore OCaml?
Since the primary motivation for adding effect handlers in Multicore OCaml is concurrency, the authors introduce effect handlers in constructing an asynchronous I/O library which retains the simplicity of direct-style programming 4.
Q3. What is the purpose of effect handlers?
Algebraic effect handlers are a modular foundation for effectful programming, which separate the operations available to effectful programs from their concrete implementations as handlers.
Q4. What is the simplest way to prevent the possibility of using continuations?
The linearity of computations is implicit in OCaml without effect handlers, but once continuations appear as first-class values the possibility of using them twice arises.
Q5. What are the alternatives to implement the continuations in effect handlers?
There are several alternatives to implement the continuations in effect handlers including free monadic interpretations [16, 17, 36], CPS translations [13, 20], and runtime strategies.
Q6. What is the server side implementation of a CPS machine?
The server side implementation is based on a generalised abstract CEK machine [12], while the client side implementation is based on a CPS translation [13].
Q7. What is the way to ensure that a continuation is not discarded?
Ensuring that a continuation is not simply discarded is harder: the system must detect when a continuation is being garbage-collected, and discontinue it with a special exception so that resource cleanup code runs.
Q8. What is the definition of a default handler?
In other words, a default handler can operationally be understood as a top level handler which encloses the entire program context including itself.
Q9. How do the authors ensure that a continuation is not used twice?
Ensuring that a continuation is not used twice is easy enough, by keeping a bit of state in the continuation, updated by continue and discontinue so that subsequent resumptions fail.
Q10. What is the way to handle asynchronous effects?
Their implementation of asynchronous effects also provides an elegant solution to handling problematic corner cases in typical operating system interfaces, such as reliable signal handling and efficiently implementing quirky system call interfaces while exposing a simple, portable interface to the developer.
Q11. What is the way to make asynchronous effects preemptive?
Using asynchronous effects the cooperative scheduler of Fig. 1 can be made preemptive, by asking the operating system to provide a periodic timer signal (using e.g. the Unix timer_create API), and adding a new clause to the scheduler:| effect TimerTick k → enqueue (continue k); run_next ()Operating systems provide several different I/O interfaces.
Q12. What is the default handler for accept?
A default handler is a convenient mechanism for ensuring that an operation invocation is always meaningful even when not in scope of a handler.
Q13. What is the average latency of a wrk2 run?
Each wrk2 run uses a fixed number of client connections that issues requests at a constant rate, and measures request latency and throughput.
Q14. What is the main difference between direct and callback-oriented code?
In addition to being more readable, direct-style code tends to be easier to debug; unlike callback-oriented code, direct-style code uses the stack for function calls, and hence, backtraces can be obtained for debugging.
Q15. What is the main idea behind the implementation of the async-await library?
Leijen [19] describes an implementation of a fullfledged async-await library implemented using effect handlers in Koka including cancellation and timeout.
Q16. What is the main difference between effect handlers and monads?
effect handlers allow concurrent programs to be written in directstyle retaining the simplicity of sequential code as opposed to callback-oriented style (as used by e.g. Lwt [34] and Async [24]).