Pure fragment of the Swarm language [001T]
- November 18, 2025
First, we go through the various types and constructs in the pure fragment of the language. Expressions in the pure fragment can be evaluated and have no side effects, in contrast to the command monad, which embeds effectful, sequenced imperative programs. Note that evaluating an expression can result in an exception being thrown or nontermination, which one might consider effects; but both of these result, semantically, in a value of \bot . Evaluating an expression cannot have side effects in the sense of computing a value successfully while also causing extra effects.
For each type or family of types, we explain typing rules for introduced and elimination forms, as well as related built-in constants.
Undefined [00GR]
- June 9, 2026
There is a built-in constant \mathsf {undefined}, with type \forall \alpha .\; \alpha . Semantically, it corresponds to \bot ; operationally, trying to evaluate \mathsf {undefined} causes an exception to be thrown.
\mathsf {Void} and \mathsf {Unit} [001V]
- November 18, 2025
Swarm has a built-in \mathsf {Void} type with zero inhabitants, and a \mathsf {Unit} type with one inhabitant (written \mathsf {()}). Their associated typing rules are standard, and no special capabilities are needed to use them.
Note that there is no built-in eliminator for \mathsf {Void}; it is easy to implement one using undefined, as in \mathsf {absurd} : \forall \alpha .\; \mathsf {Void} \to \alpha = \lambda x.\; \mathsf {undefined}.
\mathsf {Delay} [00GS]
- June 10, 2026
If \tau is a type, then \mathsf {Delay}^{\Delta }\;\tau is a type representing delayed expressions of type \tau . The annotation \Delta represents the capabilities needed to force evaluation of the contained expression.
The delay type comes with two built-in constants, \mathsf {delay} and \mathsf {force}, representing introduction and elimination forms, with typing rules as follows:
Remark [00GT]
- June 10, 2026
Note that in surface syntax for Swarm, the delay type and introduction form are both written with curly braces; we choose not to use that syntax in this formal development since it could be easily confused with syntax for capability sets.
Functions [00GU]
- June 10, 2026
If \tau _1 and \tau _2 are types, and \Delta is a capability set expression, the type \tau _1 \xrightarrow {\Delta } \tau _2 represents functions which, when applied to an argument of type \tau _1, produce a result of type \tau _2 using capabilities \Delta . We use \tau _1 \to \tau _2 as an abbreviation for \tau _1 \xrightarrow {\varnothing } \tau _2, a function which requires no capabilities to apply.
Typing rules for functions [001A]
- November 9, 2025
The typing rule for lambdas is straightforward:
Here is the typing rule for function application:
Booleans [001W]
- November 18, 2025
The \mathsf {Bool} type is standard, with values \mathsf {true} and \mathsf {false}; no special capabilities are needed to use Boolean values themselves.
The eliminator for \mathsf {Bool} values is a built-in function \mathsf {if} with type \mathsf {if} : \forall \alpha .\; \{\mathsf {Exc}(\mathsf {if})\} \Rightarrow \mathsf {Bool} \to \mathsf {Delay}^{\delta _1}\;\alpha \to \mathsf {Delay}^{\delta _2}\;\alpha \xrightarrow {\delta _1 \cup \delta _2} \alpha This says that \mathsf {if} takes a boolean value and two delayed expressions of the same type \alpha , and produces a value of type \alpha . It also tells us that evaluating the constant \mathsf {if} itself requires capability \mathsf {Exc}(\mathsf {if}), and that evaluating its full application to a boolean and two delayed expressions requires capabilities \delta _1 \cup \delta _2—whatever capabilities are required to evaluate the two branches. Of course, only one of \delta _1 or \delta _2 will actually be needed, but since we can't know which until runtime, we must conservatively require their union.
Other base types: \mathsf {Int}, \mathsf {Text}, \mathsf {Dir}, \mathsf {Key}, \mathsf {Actor} [001X]
- November 18, 2025
Swarm has various other base types such as \mathsf {Int}, \mathsf {Text}, \mathsf {Dir}, \mathsf {Key}, and \mathsf {Actor}. All of these have various types of literals as well as built-in functions for manipulating them. As just one example, the addition operator is a built-in constant with the type \{\mathsf {Exc}(+)\} \Rightarrow \mathsf {Int} \to \mathsf {Int} \to \mathsf {Int}. The details of all the other introduction forms and operators, though important, are largely straightforward and not central to the story here.
Algebraic types [00GW]
- June 11, 2026
Swarm also has algebraic types, in the form of sum types \tau _1 + \tau _2, product types \tau _1 \times \tau _2, and record types [x_1: \tau _1, \dots , x_k: \tau _k].
XXX describe each one in turn. Need to mention elim forms in particular.
Equirecursive types [00GX]
- June 11, 2026
The type \mu X.\; \tau [X] represents the recursive type which is the least solution to \mu X.\; \tau [X] = \tau [\mu X.\; \tau [X]]. Since recursive types in Swarm are equirecursive, there are no special introduction or elimination forms; a recursive type is simply equal to its unfolding. For example, the type of polymorphic lists is given by \mu L.\; \mathsf {Unit} + \alpha \times L; in order to use a list, one can simply use \mathsf {case} to pattern-match on the sum type.