Algebraic Effects

Algebraic Effects

KryhtaJS is a tiny JavaScript engine with algebraic effects, written in Rust and compiled to WebAssembly. It extends JavaScript with:

Try It

Generator Pattern

Effects can implement generators without special syntax. Yield! is just another effect:

Mutable State

State can be implemented as a pattern. The handler threads state through continuations:

Early Exit

If you don’t call resume, the computation stops:

First-Class Handlers

Handlers are values. You can store them in variables and reuse them:

Fibers

Effects enable cooperative concurrency without threads. Fork! spawns a fiber, Join! waits for it: