vic/GoDNix
{ "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.
Features
Section titled “Features”This first version supports:
- Integers: Church numeral encoding
- Anonymous functions:
x: bodysyntax - Function application: Direct application of functions to arguments
- Let bindings:
let x = value; in bodyexpressions - Addition operator: Pure Church numeral addition (
+)
Building
Section titled “Building”go build -o godnix ./cmd/godnixTesting
Section titled “Testing”Run the integration tests:
go test ./cmd/godnix/For verbose output:
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
./godnix <file.nix>Examples
Section titled “Examples”Simple Integer
Section titled “Simple Integer”42Output:
42Addition
Section titled “Addition”2 + 3Output:
5Identity Function
Section titled “Identity Function”(x: x) 7Output:
7Let Binding
Section titled “Let Binding”let x = 5; y = 3;in x + yOutput:
8Lambda Functions
Section titled “Lambda Functions”let add = x: y: x + y;in add 4 6Output:
10Architecture
Section titled “Architecture”Components
Section titled “Components”- Parser (
pkg/parser/): Full-featured Nix parser (already present) - Translator (
pkg/compiler/translator.go): Converts Nix AST to Lambda calculus terms - Compiler (
cmd/godnix/): Main application that coordinates parsing, translation, and evaluation
Translation Strategy
Section titled “Translation Strategy”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
Evaluation
Section titled “Evaluation”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
Performance
Section titled “Performance”The evaluator provides statistics after each run:
- Execution time
- Total reductions performed
- Reductions per second
Example output:
Stats:Time: 337.889µsTotal Reductions: 60 (177573.11 ops/sec)Limitations (v1)
Section titled “Limitations (v1)”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.
Future Directions
Section titled “Future Directions”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
License
Section titled “License”See LICENSE file.