Choreographic programming library for MoonBit.
moon add Milky2018/moonchortrait Location: Show + Hash {
name(Self) -> String
}
fn make_local_backend(
locations : Array[&Location],
logger~ : &Logger = make_mute_logger()
) -> Backend
async fn run_choreo[T, L : Location](
backend : Backend,
choreography : (ChoreoContext) -> T!Async,
role : L,
logger? : &Logger
) -> T struct Alice {}
struct Bob {}
impl Location for Alice with name(_) { "Alice" }
impl Location for Bob with name(_) { "Bob" }
let alice : Alice = Alice::{ }
let bob : Bob = Bob::{ }async fn simple_choreo(ctx: ChoreoContext) -> Unit {
let msg_at_alice = ctx.locally(alice, fn (_) { "Hello" })
let msg_at_bob = ctx.comm(alice, bob, msg_at_alice)
ctx.locally(bob, fn (unwrapper) { println(unwrapper.unwrap(msg_at_bob)) })
}let backend = make_local_backend([alice, bob])
run_choreo!(backend, simple_choreo, alice)
// or run_choreo!(backend, simple_choreo, bob)type Backendtype ChoreoContextfn ChoreoContext::condition[L : Location + Show + Hash](self : ChoreoContext, loc : L, c : Located[Bool, L]) -> Boolfn ChoreoContext::locally[T, L : Location + Show + Hash](self : ChoreoContext, location : L, computation : (Unwrapper[L]) -> T) -> Located[T, L]type Unwrapper[_]fn condition[L : Location + Show + Hash](self : ChoreoContext, loc : L, c : Located[Bool, L]) -> Bool