Open Work
This page records Nilakan’s design goal, the gaps between the goal and the current language, and the direction the language is expected to take. It is not a promise of syntax or a release schedule. Unless a section says otherwise, nothing here is implemented, and nothing here is proven. The other reference pages describe behavior available in the interpreter today.
Code marked “proposed” sketches an idea. Its syntax is not settled.
Nilakan aims to be a language whose programs can be proven correct, that people and language models can read and write easily, and whose design rules out whole classes of bugs instead of leaving them to testing.
Throughline
Section titled “Throughline”The core idea is: a program is a sequence of whole-state steps, and every step can be seen. A
commit loop is a table. init writes the first row. Each round reads one row and commits the next
row atomically, and the trace shows every row. This is the same structure as a TLA+ specification
(Init and Next) and as a loop with an invariant in Dafny, so the shape that is easy to trace is
also the shape that is easy to prove.
Every design decision should follow from five rules:
- Every state change is a row. State changes only when a round commits. Input and output are columns on that same sequence of rows.
- Every failure is visible. An operation that can fail either returns
errin its type or carries a condition that must be shown to hold. - Every loop can say what it keeps and why it ends. This is optional at first and checked at runtime, and can be proven later.
- Python spelling means Python meaning. Where Nilakan behaves differently, it uses a different spelling.
- Whatever the checker knows, the trace can show. Failed checks and counterexamples appear as rows.
Where The Language Stands
Section titled “Where The Language Stands”| Class of bug | Current status |
|---|---|
| Null values | Ruled out. There is no None. |
| Shared mutable state, aliasing | Ruled out. Values are copied; list and dict methods return new values. |
| Update-order bugs (swaps, Fibonacci) | Ruled out. Every update in a round reads the same row. |
| Duplicate or missing state writes | Checked before running (NLK3005, NLK3008). |
| Unhandled errors | Mostly checked. Raw indexing and / by zero still stop the program at runtime. |
| Out-of-range indexes, off-by-one | Runtime only (NLK4004). |
| Loops that never end | Runtime only. The round limit stops them (NLK5001). |
| Type errors in code without types | Runtime only. "a" + 1 fails only when it runs (NLK4001). |
| Numeric precision | Not addressed. Numbers are doubles, so 0.1 + 0.2 == 0.3 is False. |
| Hidden effects | Partly addressed. Procedures are inferred, but a definition doesn’t show it. |
| Checker disagreeing with execution | Known gap. See Commit Analysis. |
Foundations
Section titled “Foundations”These come first because the rest of the plan depends on them.
Commit Analysis
Section titled “Commit Analysis”Status: shared execution and analysis model required. Highest priority.
Error analysis currently follows source statement order while ordinary commit loops execute a dependency schedule. It also combines current and next-state facts by binding name. Runtime checks remain authoritative, but the checker can miss an error supplied through a forward temporary. The next implementation should share resolved binding versions, state phases, and conditional schedules between dependency planning, execution, and effect analysis.
Proofs depend on this. A checker that analyzes a different order from the one the program runs in cannot be the basis of a prover.
Output And Analysis Budgets
Section titled “Output And Analysis Budgets”Status: interpreter resource controls required.
The browser bounds streamed output and can terminate its execution worker. The interpreter also bounds runtime values, recursion, rounds, nesting, and trace capture. These limits do not impose an aggregate byte budget on retained output or a round’s unpublished effects. An explicit interpreter budget should cover both publication and speculative staging, with the CLI and editor using the same enforcement.
Static analysis also needs a work budget for large call graphs and binding graphs. A budget failure must report incomplete analysis rather than accepting partial evidence as a proof.
Numbers
Section titled “Numbers”Status: design agreed in principle; breaking change.
Numbers are IEEE doubles. 9007199254740993 prints as 9007199254740992, 0.1 + 0.2 == 0.3 is
False, and a number is checked to be a whole number only when it is used as an index. Floating
point also makes arithmetic hard to prove.
Direction:
- Number literals and arithmetic are exact rationals by default, so
1 / 3stays exact. Pyret does this. - Operations with irrational results, such as
sqrt, return an approximate number. Approximate numbers can’t be compared with==; you compare them within a tolerance instead. - Dividing by zero is an
errvalue or a proof obligation, never a crash or an infinity. **,//, and the usual math functions are added, in amathmodule where possible.
Exact rationals also suit solvers, because linear arithmetic over the rationals is decidable.
Effects And I/O
Section titled “Effects And I/O”Status: design direction; replaces the open question of effectful procedure syntax.
Today print and drawing calls are recorded in a per-round journal and published when the round
commits, and dropped when it rolls back. Each published output, chart, and raylib frame carries the
round that produced it, so the playground links output to its trace row and can replay recent frames
by round. Input is not recorded yet. Nilakan infers that a function is effectful when it calls
print, directly or through other functions, and then allows it only as a statement. So adding a
print to a function that returns a value is an error, and the distinction is not visible in the
function’s definition.
Direction: the commit loop is the I/O trunk. Effects happen only at commits, as part of the visible row, so they are not side effects. This is the idea behind Clean’s world-passing I/O, the input-and-output cycle of synchronous languages such as Lustre, and the Elm architecture.
- Inputs are read-only columns. The host fills them before each round: pressed keys, mouse position, time, a line of typed text.
- Outputs are primed columns. The host acts on them only when the round commits: printed text, a frame, a figure.
- The interpreter is a step function. It takes a row and its inputs and returns the next row and its outputs. The CLI and the playground are two hosts that run the same step. A host offers capabilities: the playground offers graphics and the CLI does not.
- Top-level code is one implicit round. A top-level
printis that round’s output. - The trace shows input and output. Recording the input columns makes any run replayable, which gives deterministic tests and time-travel debugging.
- Effects are declared. A procedure is marked in its definition, not only inferred.
The raylib module keeps raylib’s names and design with a Nilakan twist: a frame becomes an output
value instead of a sequence of drawing calls.
def animate(): init: x = 0 while not input.closed: x' = x + 1 if KEY_RIGHT in input.keys else x frame' = [rect(x, 0, 10, 10, BLUE), text("hi", 5, 5, 20, GRAY)] return 0Open costs:
- Reading a line in the middle of a function is no longer possible. A program sends a prompt as output and receives the answer as the next round’s input.
- The playground’s raylib host currently pauses inside a round to present a frame. It has to move to the round boundary.
User-Defined Data
Section titled “User-Defined Data”Status: syntax design required.
Nilakan has num, str, bool, err, lists, tuples, sets, and dicts, and no way to define a
type. Without that, data structures such as stacks, queues, and trees can’t be written in Nilakan,
and standard library modules can’t be either.
Direction: records and variants (tagged unions) together, with a match expression that must cover
every variant. Pyret and How to Design Programs show this is teachable: design the data first, then
write functions that follow its shape. These types keep Nilakan’s value semantics: updating a field
produces a new value.
data Shape: Circle(radius: num) Rect(width: num, height: num)
def area(s: Shape) -> num: a = match s: Circle(r): 3.14159 * r * r Rect(w, h): w * h return aStatic type inference for code without type contracts belongs with this work, so that errors such as
"a" + 1 are reported before the program runs.
Function Values
Section titled “Function Values”Status: open question.
Functions are not values. As a result, map, filter, sorting by a key, and a priority queue with
a custom order can’t be written in Nilakan. Closures complicate specifications and proofs. A middle
ground is to allow passing named, pure, top-level functions as values, with no closures or lambdas.
Specifications And Proof
Section titled “Specifications And Proof”Status: design direction. No solver exists yet, so no diagnostic or document may claim that a program is proven.
A commit loop is already a transition system. Proving a property of a loop means showing that the first row satisfies it and that every round preserves it. The language needs a way to write that property down:
def total(xs: list[num]) -> num: init: i = 0; acc = 0 while i < len(xs): invariant: 0 <= i and i <= len(xs) decreases: len(xs) - i acc' = acc + xs[i] i' = i + 1 return acc- Loop clauses.
invariantanddecreasessit under the loop’sregime, which will replacepragma. They use Dafny’s words because people and language models already know them. - Refinements on contracts. Type contracts can carry conditions, such as
xs: list[num] where len(xs) > 0on a parameter or a condition on a result. This is how indexing and division become provably safe instead of stopping the program. - Check at runtime first. Clauses are evaluated as the program runs, and a violation is reported at the trace row where it happened. Whiley recommends this path: test specifications, then prove them.
- Prove later. A solver, for example Z3 compiled to WebAssembly, discharges the same clauses. A counterexample is a sequence of rows, so the trace panel can display it.
- Cheap checks need no solver. A loop whose condition reads only names that are never primed cannot end. The checker can report that before the program runs.
Avoid full dependent types and any split between proof-only (“ghost”) code and real code. Both make verification harder for people and for language models.
Accumulation Verification
Section titled “Accumulation Verification”Status: evaluator and verifier implementation required.
acc_prime: sequential is executable. The five other recognized modes report NLK3013. Replay,
closure, lawful reduction, and finite convergence/confluence verification require their own
execution and evidence rules; a pragma name cannot substitute for those checks. These modes move
under regime with the loop clauses above.
Explicit Rebinding
Section titled “Explicit Rebinding”Status: optional language design.
A binding’s first explicit type contract now persists. Equivalent annotations can repeat; a changed contract is rejected. Use a different binding name when a value needs another contract. Any future explicit conversion or rebinding operation needs its own syntax and failure rules.
Modules
Section titled “Modules”Status: design direction. Not started.
Built-in modules are TypeScript tables wired into the interpreter, and their help text and data are spread across several packages. The module system needs to let maintainers add or update a module without changing the interpreter.
Direction:
- One
.nlkfile is each module’s front door. It holds names, types, contracts, and doc comments. The checker and the editor’s completion and hover read only this file. - Modules come in three kinds. A module can be written in Nilakan, in Nilakan with some
functions implemented in TypeScript, or entirely in TypeScript. A function implemented in
TypeScript is declared
externin the.nlkfile, as in Gleam’s@external. An all-TypeScript module is a.nlkfile ofexterndeclarations. - Write it in Nilakan first. TypeScript is for host access and speed. A TypeScript version of a Nilakan function must pass the same tests, as Python requires of its C accelerators (PEP 399).
- Externs stay within the model. An
externis pure unless it declares the input or output columns it uses. Only modules shipped in this repository, written by its maintainers, may containextern. Classroom and third-party modules are pure Nilakan. Elm and Gren make the same choice to keep their guarantees. - Host capabilities are checked at import. A module that needs graphics fails when it is imported under a host without graphics, before the program runs.
- Values are displayed by type. A host maps a type to a renderer, for example a figure to SVG. Data crossing into TypeScript is plain values. Things that live in the host, such as a window, are handles.
Good first candidates are a math module and a collections module, both mostly Nilakan, and then
rewriting plot so that only its SVG renderer stays in TypeScript.
Readability For People And Language Models
Section titled “Readability For People And Language Models”Status: small changes, mostly independent of the larger work.
Language models will write Python, so Python spellings that mean something else in Nilakan cause predictable mistakes. Known cases:
print("hi")prints"hi"with quotes. Printing should show strings without quotes and keep quotes inside lists and dicts.**and//are missing, and there is nosqrt,abs,round,min, ormax.seen.get(w) catch 0 + 1parses asseen.get(w) catch (0 + 1). The checker should warn whencatchis followed by an arithmetic expression without parentheses.- With a parameter typed only as
list,w = words[i]is rejected because an item may be anerrvalue, whilelist[str]works. The diagnostic should suggest adding the element type. - A top-level
init:reports a generic syntax error before the useful one. It should say to put the loop inside a function, or top-level loops should be allowed.
Other rules:
- One source of truth. The tour says every function ends with a single
return, but early returns are allowed. Documentation that contradicts the implementation misleads language models more than missing documentation does. - Diagnostics in plain words. Priming a parameter reports “must resolve to commit depth 1”; it
should say that a parameter cannot be updated and must be copied into
init:first. - Diagnostics for tools. A JSON diagnostic output in the CLI would let language-model agents fix
programs in a loop using the existing
help:lines.
Order Of Work
Section titled “Order Of Work”Done: plot and raylib are the first built-in modules, and playground output is linked to the
rounds that produced it.
- Fix Commit Analysis, so that checking and execution share one model.
- Make numbers exact while there are few programs to migrate.
- Add user-defined data and static type inference, then decide on function values.
- Move effects onto the commit trunk with declared procedures, and redesign modules on top of it,
starting with
math. - Add
invariant,decreases, andwherechecked at runtime and shown in the trace; add a solver after that.
The readability fixes can land at any point.
Prior Art
Section titled “Prior Art”- Transition systems: TLA+, Lucid, Lustre.
- I/O as a single sequence: Clean I/O, Elm commands and subscriptions, Roc platforms, functional core and imperative shell (Boundaries).
- Verification: Dafny, SPARK, Whiley, Liquid Haskell, and the vericoding benchmark, in which language models succeeded on 82% of Dafny tasks and 27% of Lean tasks.
- Numbers: Pyret numbers.
- Data definitions: Pyret structured data.
- Modules and foreign code: Gleam externals, PEP 399, Elm interop limits, WebAssembly interface types.
- Value semantics: Mutable Value Semantics.