Skip to content
vic

vic/GoDNix

A Nix language compiler into Delta Interaction Nets

vic/GoDNix.json
{
"defaultBranch": "main",
"description": "A Nix language compiler into Delta Interaction Nets",
"fullName": "vic/GoDNix",
"homepage": "",
"language": "Go",
"name": "GoDNix",
"pushedAt": "2025-11-23T14:51:29Z",
"stargazersCount": 0,
"updatedAt": "2025-11-23T14:51:32Z",
"url": "https://github.com/vic/GoDNix"
}

Go D-Nix — A Nix compiler into Delta Interaction Nets.

Godnix is a compiler that translates Nix expressions using the GoD-Net interaction net reduction engine.

This first version supports:

  • Integers: Church numeral encoding
  • Anonymous functions: x: body syntax
  • Function application: Direct application of functions to arguments
  • Let bindings: let x = value; in body expressions
  • Addition operator: Pure Church numeral addition (+)
Terminal window
go build -o godnix ./cmd/godnix

Run the integration tests:

Terminal window
go test ./cmd/godnix/

For verbose output:

Terminal window
go test -v ./cmd/godnix/

The test suite includes:

  • Examples from examples/ directory
  • Inline expression tests
  • Church numeral encoding/decoding
  • Error handling for unsupported features
  • Direct translator unit tests
Terminal window
./godnix <file.nix>
examples/simple.nix
42

Output:

42
examples/add.nix
2 + 3

Output:

5
examples/identity.nix
(x: x) 7

Output:

7
examples/let.nix
let
x = 5;
y = 3;
in
x + y

Output:

8
examples/lambda.nix
let
add = x: y: x + y;
in
add 4 6

Output:

10
  1. Parser (pkg/parser/): Full-featured Nix parser (already present)
  2. Translator (pkg/compiler/translator.go): Converts Nix AST to Lambda calculus terms
  3. Compiler (cmd/godnix/): Main application that coordinates parsing, translation, and evaluation

Godnix translates Nix expressions to pure Lambda calculus:

  • Integers → Church numerals: n = λf. λx. f^n x
  • Addition → Church numeral addition: λm. λn. λf. λx. m f (n f x)
  • Functions → Lambda abstractions: x: bodyλx. body
  • Let bindings → Function application: let x = v in b(λx. b) v
  • Application → Standard application: f x → Lambda application

The compiled Lambda terms are evaluated using the godnet deltanet reduction engine, which implements optimal reduction through interaction nets. This provides:

  • Parallel reduction opportunities
  • Optimal sharing of computations
  • Efficient memory usage

The evaluator provides statistics after each run:

  • Execution time
  • Total reductions performed
  • Reductions per second

Example output:

Stats:
Time: 337.889µs
Total Reductions: 60 (177573.11 ops/sec)

This first version has intentional limitations:

  • Only integers (no floats, strings, lists, sets)
  • Only + operator (no other arithmetic or comparison)
  • No built-in functions beyond +
  • No attribute sets or recursive bindings
  • No imports or file system operations

These limitations allow focusing on the core compilation pipeline. The full Nix parser is available, so adding support for more features is straightforward.

Potential additions for future versions:

  • More arithmetic operators (-, *, /)
  • Boolean operations and conditionals
  • Lists and list operations
  • Attribute sets
  • Built-in functions (map, filter, fold)
  • String operations
  • Native functions for performance-critical operations

See LICENSE file.