Algebraic Effects
KryhtaJS is a tiny JavaScript engine with algebraic effects, written in Rust and compiled to WebAssembly. It extends JavaScript with:
perform Effect!(args)triggers an effect and captures the continuationhandle { } with { }catches effects and decides how to resumeresume(value)is a one-shot continuation that resumes execution- First-class handlers can be stored and reused
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: