Programming with Effects
Code often has a happy path to the goal, but needs to consider a lot of error cases as well. These error cases deviate from the path and need to be handled. In software, we can leverage several solutions differing in their power to similar problems:
- Error codes. A simple solution is to return an error code in case of an error and handle that.
- Exceptions. Exceptions enable a clean separation between the code that raises an exception and the code that handles it.
- Coroutines. Besides raising an exception and therefore stopping code, alternatively, a coroutine can suspend execution with a question and other code can resume the coroutine with an answer.
- Continuations. Further, it might be possible to create a copy of the current program execution state, resume execution and then later backtrack and continue execution with a different value.
At some point we no longer consider the exceptions as "side"-effects, i.e., things which went wrong, but instead we use the continuations as equally important parts of the primary goal of some functionality -- an effect. Effect handlers as generalizations of exception handlers offer interesting new ways to modularize software. Effects and co-effects can accurately represent additional capabilities and restrictions on parts of code.
Seminar
In the seminar:
- Introduce the idea of programming with effects with example programs using Koka
- If necessary, look for older papers that introduce and explain the idea in more simpler terms
- Pick a recent paper on programming with effect (such as Associated Effects) and explain the new features and additional concepts
- Is it possible to express the same programs in Flix and Koka? What is the difference?