Hi, I’m excited to share Theseus, an effect system library supporting algebraic effects (including nondeterminism and coroutines), higher order effects, guaranteed finalizers, and semantics that do not change regardless of how you order interpreters. The project’s readme (linked above) has a tutorial, a showcase, and annotated source files explaining how it works.
Copying a couple of those links directly:
- A tutorial walking you through creating an effect for interacting with the terminal, testing the effect, creating a higher order effect, and understanding private and public effects.
- A showcase providing an example of something that other effect systems can struggle with.
To make sure it worked in the real world, I ported an old project over to Theseus called the Daily Reporter. It scrapes the web and sends Matrix messages with what it finds. Since that migration was successful, I figured now would be a good time to share Theseus.
So how does it work? Theseus uses a higher order Freer Monad to merge algebraic and higher order effects, and it uses a new class called ControlFlow to manage finalizers and order independent interpretations. There’s more of an explanation here although I’d recommend going through at least the tutorial first. Theseus makes some trade offs to accomplish these goals. In particular the ControlFlow mechanism requires that Theseus modify the semantics of nondeterminism and coroutines a bit. Nondeterminism ends up running in more of a breadth first style, and suspended functions need to be used linearly (otherwise finalizers might get duplicated or skipped). Overall though I think these are useful trade offs to make! You lose out on some control flow flexibility, but in exchange you get easy resource management.
If anyone has questions about Theseus, I’d be happy to answer them! If anyone has ideas for improving Theseus, I’d be happy to hear those too!