# Welcome to MUL

MUL, the Modular Universal Language, starts from one question: what should a
programming platform look like when a large share of the code is written,
read and changed by AI agents? Our answer has two parts. One is a small,
statically typed source language. The other is a typed, verified
intermediate representation (IR) and a code graph, on which agents do short,
checkable operations: plan, review, apply, verify.

This site is the first public home of the project. This post covers what
works today, how it is checked, and where it goes next.

## What compiles today

MUL is young, and the language reference describes only what the compiler
accepts now: `i32`, `bool` and `string`, checked arithmetic, comparisons,
short-circuit logic, functions and recursion, `let` and `var`, block scopes,
`if`/`else`, `while`, and effects in signatures. That is enough for programs
like this one:

```mul
module demo

fn collatz(n: i32) -> i32 {
    var steps = 0
    var x = n
    while x != 1 {
        if x % 2 == 0 {
            x = x / 2
        } else {
            x = 3 * x + 1
        }
        steps = steps + 1
    }
    return steps
}

pub fn main() -> i32 io {
    print("steps for 27:")
    return collatz(27)
}
```

The value `main` returns is the exit code of the process, as in C. Running it
prints the line and exits with 111.

## Effects are part of the signature

A function that prints is marked `io`; a function without a mark is `pure`
and may not call an `io` function. The rule is checked at compile time, so
an agent reading a signature knows what the function may do without reading
its body:

```console
$ mul check effects.mul
effects.mul:9:12: error[MUL-T013]: a `pure` function cannot call the `io` function `greet`
  |     return greet()
  |            ^^^^^^^
```

Every error has a stable code like `MUL-T013`. The
[errors page](/errors/) lists each one with a fix, and the codes do not
change between releases. A program, or an agent, can match on the code
instead of parsing a message.

## Every result is computed twice

A program goes through the parser and the type checker, is lowered to an SSA
IR, and the verifier checks that IR (dominance, types, effects) before
anything runs it. Then there are two backends: a reference interpreter, and
Cranelift, which compiles the same IR to native code just in time or into an
executable. The test suite runs every golden case, every conformance case and
every code block in the reference through both, and fails when they
disagree. Overflow, division by zero and recursion that is too deep stop the
program with the same `MUL-R*` error in both backends.

The run-time rules are written down as numbered rules (`SEM-01` to `SEM-20`
in RFC-003), and each rule has at least one conformance case. The
[examples gallery](/examples/) shows the verified IR and the output of each
example, as the compiler printed them when this site was built.

## Tokens for the same program

MUL is measured by how many tokens it takes to get a task done correctly.
The first half of that, the size of the program, is already measurable:
`mul tokens` compares a MUL file with the same program in other languages.
The prime counter from the examples, stored in the compact layout, is 106
tokens in MUL, 143 in Go, 153 in PHP and 164 in C by the built-in estimate,
which is fitted to GPT-style tokenizers. Laid out for reading, the same MUL
program is about as long as the Go one; written compactly, as an agent
writes it, it is the shortest of the four. The [benchmarks page](/benchmarks/) has every pair,
regenerated with each build. The estimate is not any one model's tokenizer,
so the numbers show a direction, not an exact figure.

## What comes next

The work is planned in stages, and each stage ends with something that runs.
The first stage, a compiler for a small language that checks every result
twice, is what this post describes. The second, identity and persistence, has
landed: stable symbol ids and hashes, `mul inspect`, the `.mulb` binary format
with an integrity check, errors that point to the MUL source, and fuzzing of
the readers. [Its own post](/blog/identity-and-persistence/) covers it and
lists what is still open. The stages after it:

- **Go patch mode.** A Go adapter reads a repository into the code graph,
  and `mul plan` and `mul apply` change it with minimal byte-range patches
  that `gofmt`, `go build` and `go test` must accept.
- **An operation engine.** Version bumps and renames as transactions, with an
  audit trail and rollback.
- **An API for agents.** The same operations over JSON-RPC, so an agent can do
  a whole change without reading source files.

The full plan, and the reasoning behind it, is in the
[design papers](/papers/) (English edition and the Polish original).

## Try it

MUL builds from source with a pinned Rust toolchain:

```console
$ make build
$ ./target/release/mul run examples/hello.mul
Hello, world!
```

`mul guide` prints the whole current language on one page, short enough
to paste into a model's prompt. If you write MUL with an agent, start there.
