MultiChor is a library for writing choreographic programs in Haskell.
That means you write one program, a "choreography" which seamlessly describes the actions of many communicating machines; these participants can be native Haskell threads, or various humans' laptops communicating over HTTPS, or anything in between. Each of these "endpoints" will "project" their behavior out of the choreography.
Choreographies aren't just easier to write than distributed programs, they're automatically deadlock-free!
MultiChor uses some of the same conventions and internal machinery as HasChor, but the API is incompatible and can express more kinds of choreographic behavior.
Choreo ps m a
.
ps
is a type-level list of parties participating in the choreography,m
is an monad used to write local actions those parties can take (often this is simply IO
),a
is the returned value, typically this will be a Located
or Faceted
value as described below.Located ls a
is a single a
known to all the parties listed in ls
.
In a well-typed choreography, other parties, who may not know the a
, will never attempt to use it.(s, v) ~> rs
, a sender s
sends the value v
to all of the recipients in rs
, resulting in a Located rs v
.enclave
and naked
combine to form cond
.
(parties, guard) `cond` (\g -> c)
unwraps a Located parties g
for use as a naked g
in the conditional choreography c
."alice"
in a choreography as a String
or a Proxy "alice"
,
they're specified by a "proof" that the type-level "alice"
is present in the choreography and has access to the relevant values.
MultiChor provides utilities to write these proofs compactly.fanOut
lets a single party send different values (of the same type a
) to a list of parties rs
, resulting in a Faceted rs a
.fanIn
lets a list of parties ss
each send a value to the same parties rs
, resulting in a Located rs (Quire ss a)
.x :: Faceted ps qs a
represents distinct a
s known to each of ps
respectively; the parties in qs
know all the a
s.parallel
lets many parties perform local monadic actions in parallel using their Located
and Faceted
values;
the return is Faceted
.congruently
lets many parties perform the same pure computation in parallel, using only their Located
values;
the return is Located
.Many example choreographies are presented in the examples directory.