algoroutine
Light-weight algebraic effect (algebraic goroutine) in Rust.
Using go!
macro just as Haskell's do notation while we use algebraic effects
instead of monads to avoid monad's composition issue.
Only one-shot (linear) algebraic effect based on coroutine is supported.
Therefore we need nightly compiler to transform code.
Main macros and combinators
go!
macro to run effects and coroutines, just like?
and.await
.Coroutine.map
to map results.Coroutine.and_then
to chain operations.
Handler
Currently handlers can only be built by hand. There's no easy way to combine.
Example
Logging and mutable states
let prepare = |_: | ;
let logic = |_: | ;
// Now we can use different ways to interpret `Log` and `State` effects!
let mut handler: = new;
let ans = handler.handle;
dbg!;
To inject effects, we don't use coproduct
, just From
!
See examples/logging_and_states for details.
Exception
let div =
|: | ;
let logic =
|_: Context| ;
let mut handler = new;
let ans = handler.handle;
dbg!;
See examples/exception for details.
Event loop
let logic =
|| ;
See examples/event_loop for details.
Fun facts
goroutine
andgo
syntax is cool (but golang's type system is terrible)algebraic effect
is coolalgebraic goroutine (algoroutine)
is probably bad ;)
TODO
- Macros for declare effect types
- More auto-injective traits
- Remove boxes for better performance