Sign in

    moonchor

    Choreographic programming library for MoonBit.

    Choreographic
    MoonBit
    Download zip
    Author
    Version
    0.9.2
    License
    Apache-2.0
    Last updated
    last year
    Downloads
    145

    #Moonchor: Choreographic Programming Library for MoonBit

    #Installation

    moon add Milky2018/moonchor

    #Examples

    Check examples

    #Basic APIs

    trait 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

    For example, you can define some roles/locations by implementing the Location trait:

    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::{ }

    Define a simple choreography: Alice --msg-> 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)) })
    }

    Then you can run the choreography:

    let backend = make_local_backend([alice, bob])
    run_choreo!(backend, simple_choreo, alice)
    // or run_choreo!(backend, simple_choreo, bob)

    #Todo

    #Further Readings

    Location

    pub(open) trait Location : Show + Hash {
    name(Self) -> String
    }

    Logger

    pub trait Logger {
    info(Self, String) -> Unit
    }

    PolyLocation

    pub(open) trait PolyLocation : Location + ToJson +
    FromJson
    {
    }

    Backend

    type Backend

    Backend::check_location

    fn Backend::check_location(self : Backend, loc : Location) -> Bool

    Backend::get_logger

    fn Backend::get_logger(self : Backend) -> Logger

    ChoreoContext

    type ChoreoContext

    ChoreoContext::broadcast

    fn ChoreoContext::broadcast[T :
    FromJson
    + ToJson, L : Location + Show + Hash](self : ChoreoContext, loc : L, value : Located[T, L]) -> T
    Broadcast a message to all locations.

    ChoreoContext::comm

    fn ChoreoContext::comm[T :
    FromJson
    + ToJson, From : Location + Show + Hash, To : Location + Show + Hash](self : ChoreoContext, from : From, to : To, value : Located[T, From]) -> Located[T, To]
    Communication between two locations.

    ChoreoContext::locally

    fn ChoreoContext::locally[T, L : Location + Show + Hash](self : ChoreoContext, location : L, computation : (Unwrapper[L]) -> T) -> Located[T, L]
    Local computation at the given location.

    ConsoleLogger

    type ConsoleLogger

    Located

    type Located[T, _]
    Represents a value located at a specific location.

    MuteLogger

    type MuteLogger

    Unwrapper

    type Unwrapper[_]
    The unwrapper is used to unwrap located values in the computation. It is passed to the computation function as the only argument.

    Unwrapper::unwrap

    fn Unwrapper::unwrap[T, L](_ : Unwrapper[L], v : Located[T, L]) -> T
    Unwrap a located value.

    alert

    fn alert[Any](msg : String) -> Any

    check_location

    fn check_location(self : Backend, loc : Location) -> Bool

    comm

    fn comm[T :
    FromJson
    + ToJson, From : Location + Show + Hash, To : Location + Show + Hash](self : ChoreoContext, from : From, to : To, value : Located[T, From]) -> Located[T, To]
    Communication between two locations.

    get_logger

    fn get_logger(self : Backend) -> Logger

    locally

    fn locally[T, L : Location + Show + Hash](self : ChoreoContext, location : L, computation : (Unwrapper[L]) -> T) -> Located[T, L]
    Local computation at the given location.

    make_console_logger

    fn make_console_logger() -> ConsoleLogger

    make_local_backend

    fn make_local_backend(locations : Array[Location], logger~ : Logger = ..) -> Backend

    make_mute_logger

    fn make_mute_logger() -> MuteLogger

    run_async

    fn run_async(f : () -> Unit) -> Unit

    run_choreo

    fn run_choreo[T, L : Location + Show + Hash](backend : Backend, choreography : (ChoreoContext) -> T, role : L, logger? : Logger) -> T
    Run a choreography in the given location and backend. Default logger is the backend logger.

    suspend

    fn suspend[A](f : ((A) -> Unit) -> Unit) -> A

    suspend_err

    fn suspend_err[A](f : ((A) -> Unit, (Error) -> Unit) -> Unit) -> A!Error

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io