muro-lang.dev / docs
Lean
muro emit path.muro --backend lean checks the book and writes <stem>.lean beside it. The file needs Lean 4 core only: no Mathlib, no Lake package. lean <stem>.lean elaborates it. Every definition is total. The file has no sorry, no partial, no unsafe, and no axiom.
muro emit tree.muro --backend lean
muro emit tree.muro --backend lean --namespace My.Tree
muro emit examples/ping.muro --backend lean
lean ping.leanWhat is emitted
Every definition sits in one namespace. Absent --namespace, it is the book stem in UpperCamel: keyed-release.muro is KeyedRelease. A name that is not a Lean identifier keeps its spelling between « and », so size-t2 is «size-t2». A name already taken, by a data type, a run, a helper, or another machine, gains a numeric suffix (Ping_2, pingStep_2).
-
A
datatype is aninductive. ItsTypeparameters stay. A value index and an erased field are dropped. It derivesRepr,BEq,DecidableEq, andInhabitedwhere Lean can: a type that holds a function derives none of the first three, and a nested type derives noDecidableEq. -
A
runis adef. Types and runs that refer to each other are onemutualblock. Lean checks termination itself. -
NatisNat.U8,U32,U64, andI64areUInt8,UInt32,UInt64, andInt64, with the rules ofMuro.Word: wrapping arithmetic, checked arithmetic asOption, total shifts, signed order forI64, and division and remainder that arenonefor a zero divisor and for theI64minimum by-1.BoolisBool,OptisOption, a pair is×, a string isString, andBytesandSliceareByteArray. A function value is a Lean function. -
A closed
evidenceequation{f a ≡ b : T}, the same equations--backend exunitcollects, istheorem name : f a = b := rfl. Lean’s kernel reduces both sides when the file is elaborated, so the equation is checked a second time by a separate kernel. An equation the collector skips is a comment that names the reason. - A session is one finite state machine. A choreography is one monitor. A family of a choreography is that monitor, one copy per key. A keyed family is one dispatcher. The same file holds the data, the runs, the machines, and the evidence theorems.
The match of an empty type, which the book’s proof makes unreachable, is panic!. That call needs an Inhabited instance of the result type: Lean will refuse the file if the type does not have one (for example a data type that does not derive Inhabited, or whose constructors do not give Lean enough to synthesize one). Spec and evidence proofs are not emitted. A step does not use panic! for an event the host supplies. It returns Except.
A session
A session is three inductives and a step. The state inductive has invalid, one constructor for each resting position, done, stuck, and stop when a failure arm ends there. The label inductive is the action: send, recv, pick0, pick1, bit0, bit1, one constructor for each case tag, down when the book marks a party, or idle when the protocol has no action. The error inductive is illegal and badState. Each derives Repr, BEq, and DecidableEq. The state and the label also derive Inhabited.
step takes the state and the label and returns Except err state. The label is the action. A payload value is not an argument, so a Nat is not checked again. A constructor, a bit, or a pick is the label, because the next state depends on it. new is the start state. done is true only at done. invalid with any label is badState. Any other pair the protocol does not list is illegal. down is legal on a state whose failure arm ends at done or stop.
When the state×label space has at most 96 pairs, one decide theorem says that every pair is an accepted next state the machine lists, or an error, and one decide theorem says that done is true exactly at done. decide has no instance for Except, so each equation is a Bool match. A larger finite machine names the pair count and has one rfl example per accepted step. Both are kernel checks. There is no native_decide.
A choreography
A choreography is the same shape of monitor. Roles, messages, and choices are inductives. An event is a message, the sender, the receiver, and the label, or a choice, the role and the label. step takes the state and the event and returns Except. A unit payload is not checked again. The accepting state is done, and the same decide or rfl theorem covers the finite event space.
A family of a choreography keeps one copy of that monitor per key, in its own namespace. new starts at the shared preamble. stepShared takes one preamble step, and it is illegal once the preamble is done. step takes a key and an event, and it is illegal while the preamble is open. A key with no row yet continues from the shared state. sharedDone is true when the preamble is done. new.shared is the start state, proved by rfl. The key set is unbounded, so the family has no decide theorem over keys.
A keyed family
A keyed family is a dispatcher over rows. The state is a structure: the rows, the departed set, the tick, the floor, the next id, the once steps, and the member keys. The rows and the departed set are lists, so the state is finite for any finite set of keys and #eval can run it. new is the empty dispatcher. A for every key step is present from the start: open when it has no hold, held when it is held until a kind. The next id starts after those steps.
arrive, resolved, withdraw, waiting_on, snapshot, skip, drop_key, skip_below, revert, and close_keys each return Except. waiting_once is emitted when a once step is held until a kind. drop_key returns the released rows along with the state in that case, and the state alone otherwise. The error inductive is badState, duplicate, departed, unknown, held, opened, resolved, withdrawn, heldBy, live, kind, index, unmarked, unfinished, closed, and oneWay. Those are the atoms Muro.Family.Step returns. badState is a state the dispatcher cannot read. unmarked is revert or once: the family is not marked may revert, or it has no once step held until a kind. That call does not read the state. A constructor marked never reverted is oneWay, checked before the row is put back. may redeliver is a comment. It is not a method.
The phase is opened, held, or resolved. A snapshot spells the open phase as the string "open". new.floor is -1 and new.next is the number of once steps, each proved by rfl. The key set is unbounded, so there is no decide theorem over keys.
A temporal declaration in a book that has a session or a choreography is two comments: the declaration is not emitted, and the key set is unbounded, so the formula is not a decide theorem. The checker still decides the formula. This file does not decide it again.
Names
Types, runs, evidence theorems, and constructor short names are claimed
against one reserved set: Lean core names, the runtime helpers, and
every unqualified identifier the emitted image itself writes (rfl in
:= rfl and by rfl, min in a shift, linter in the header, and
not in the choreography and family wrappers). The set is derived
by scanning the Lean sources and string literals under
lib/muro/emit/lean*, so a later helper is reserved when the backend is
recompiled. A colliding name is emitted as base_2 (then base_3, …)
at every use site: a constructor named true or some becomes
true_2 or some_2 in the inductive, in patterns, in applications, and
in theorems. Two inductives may still share a short name (Tree.leaf
and Bush.leaf).
What is refused
A stream is lean: stream in <run>. A run whose parameter type is a type variable is lean: opaque in <run>. A protocol the machine image does not represent is lean: unsupported protocol. A run case inside a session is lean: run case. A session whose next state carries an argument, or whose transition is not one state, is lean: unsupported session <name>. The step is the label, and that argument is a value the finite machine does not store. A session of more than 256 states is lean: unsupported session (<count>). A choreography the monitor cannot represent is lean: unsupported choreography <name>, and one of more than 256 states is lean: unsupported choreography (<count>). A family the dispatcher cannot represent is lean: unsupported family. A prepare error that is not one of those is printed as the checker printed it, including seen is not a state machine, cannot call run, failure arm continues the protocol, and dual jump.
A temporal declaration with no session and no choreography to drive it is lean: temporal <name> is not emitted. A family in that same position is lean: family <name> is not emitted. A temporal declaration is refused before a family.
Source on GitHub
· fetched from murolang/muro manual/