Swarm command monad [001U]
- November 18, 2025
If \tau is a type, \mathsf {Cmd}^{\Phi }\;\tau is the type of commands which can be executed in requirement context \Phi , might have some effects, and will ultimately result in a value of type \tau .
Built-in commands [0018]
- November 9, 2025
Many built-in commands have simple typing rules like the following:
Some built-in commands take arguments, but they typically have a similar typing rule, with no capabilities on the arrows. For example, no special capabilities are required to evaluate the application \mathsf {turn}\; \mathsf {left}.
Bind [0019]
- November 9, 2025
The basic rule for bind (aka sequencing) in the \mathsf {Cmd} monad is as follows:
Note that this rule corresponds to a particular evaluation strategy, namely, evaluating c_1 and c_2 lazily, at the time c_1;\; c_2 is executed. If we instead wanted to evaluate c_1 and c_2 eagerly, we would need a different rule:
def f : Int -> Cmd Unit = ... end def g : Dir -> Cmd Unit = ... end def example = f 3; g north endWhen are
f 3 and g north evaluated? Under the first rule above, they would be re-evaluated every time example is executed. Under the second rule, they must be evaluated eagerly, when the definition of example is evaluated.As another example, consider the standard definition
def doN : Int -> Cmd a -> Cmd Unit = \n. \c.
if (n == 0) {} {c ; doN (n-1) c}
end
Under a lazy evaluation semantics for sequencing, a call to doN 10 move expands lazily, expanding one step each time the next move is executed. Under an eager semantics, a call to doN 10 move expands immediately into a fully unrolled sequence of 10 move instructions. There are certainly scenarios where we would want this eager unrolling (for efficiency, or in order to pass a fully unrolled program to a child robot that therefore does not need any complex devices to run it), but lazy evaluation is probably the better default, perhaps with a special "eager sequence" operation provided as well. Consider the example of a forever function that calls the same command in an infinite loop: under eager evaluation, this would simply go into an infinite loop generating an infinite program without ever executing anything!
However, we can also bind the result of c_1 in c_2, in which case we do not even have the option to evaluate c_2 eagerly (unless we wanted to implement partial evaluation of open terms). The rule for x \leftarrow c_1;\; c_2 is therefore:
Require [00GZ]
- June 12, 2026
There is a special \mathsf {require} directive which requires a specific device to be equipped. Given the framework for requirements tracking, the typing rule is straightforward:
Stock [00H0]
- June 12, 2026
Similarly, there is a special \mathsf {stock} directive which requires a certain number of a specific entity to be in the inventory, with a similarly straightforward typing rule:
Build [00H1]
- June 12, 2026
When a robot (the "parent") wishes to build another robot, it can execute \mathsf {build}\;p in order to create a robot (the "child") running program p. There are several things to take into consideration here:
- Of course, the parent robot must have the capability to execute \mathsf {build}.
- The child robot should be the one to evaluate and execute p.
- The child robot must have the capabilities needed to evaluate and execute p. Hence, it must have a set of equipped devices which provide the necessary capabilities, and hence the parent robot must take these devices from its inventory and equip them on the child robot at build time.
- The program to be run by the child robot may also explicitly require certain devices to be installed, and certain inventory to be present. The parent robot must also provide these things to the child robot from its inventory at build time.
These considerations lead us to the following typing rule for \mathsf {build}:
- First, the premise states that p must be a delayed command. The reason for requiring the command to be wrapped in a delay is to make clear that any evaluation of the command is to be carried out by the child robot.
- The conclusion states that \mathsf {build}\;p is a command, producing a value of type \mathsf {Actor} (a reference to the child robot). The only capabilities needed by the parent robot to evaluate \mathsf {build}\;p are \Delta _1, the capabilities needed to evaluate p.
- The only capability needed to execute \mathsf {build}\;p is \mathsf {Exc}(\mathsf {build}).
- Executing the \mathsf {build} command does not require any specific devices to be equipped; any device which provides the \mathsf {Exc}(\mathsf {build}) capability will do.
- Executing the \mathsf {build} command does require inventory. In particular:
- The child robot will require capabilities \Delta _2 (to evaluate the delayed command) and \Delta _3 (to execute the command); and it specifically must have devices D equipped. Thus we use the provisioning oracle \mathsf {provision}(\Delta _2 \cup \Delta _3, D) to compute a set of devices to install.
- We convert this to an inventory, and union it with the inventory I specifically required to execute p.
- The result is the inventory required of the parent robot to execute \mathsf {build}\;p, since it will need to be transferred to the child robot.
Equip/unequip [00H2]
- June 12, 2026
As discussed previously, the \mathsf {equip} and \mathsf {unequip} commands allow robots to move devices between their inventory and equipped set. Unlike \mathsf {stock} and \mathsf {require}, to allow for necessary flexibility, these commands take an arbitrary expression that evaluates to the name of a device. So, conservatively, we must use generic typing rules that do not interact with the requirements system at all.