{"id":51431361,"url":"https://github.com/no-way-labs/mo","last_synced_at":"2026-07-05T04:02:31.239Z","repository":{"id":369129136,"uuid":"1159430673","full_name":"no-way-labs/mo","owner":"no-way-labs","description":"Mo is a strict functional language whose OCaml compiler generates efficient imperative Zig — no ownership annotations, no garbage collector. Linearity inference, stateful pattern fusion, and opaque linear handles let pure functional code match or beat hand-written Zig on memory across 5 benchmarks.","archived":false,"fork":false,"pushed_at":"2026-07-03T17:40:26.000Z","size":463,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-07-03T19:25:19.191Z","etag":null,"topics":["compiler","compiler-optimization","functional-programming","language-design","linear-types","ocaml","programming-language","stream-fusion","systems-programming","zig"],"latest_commit_sha":null,"homepage":null,"language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/no-way-labs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-16T18:09:17.000Z","updated_at":"2026-07-03T17:40:29.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/no-way-labs/mo","commit_stats":null,"previous_names":["no-way-labs/mo"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/no-way-labs/mo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/no-way-labs%2Fmo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/no-way-labs%2Fmo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/no-way-labs%2Fmo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/no-way-labs%2Fmo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/no-way-labs","download_url":"https://codeload.github.com/no-way-labs/mo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/no-way-labs%2Fmo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35142824,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-05T02:00:06.290Z","response_time":100,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compiler","compiler-optimization","functional-programming","language-design","linear-types","ocaml","programming-language","stream-fusion","systems-programming","zig"],"created_at":"2026-07-05T04:02:30.443Z","updated_at":"2026-07-05T04:02:31.227Z","avatar_url":"https://github.com/no-way-labs.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mo\n\n**Pure functional code. Imperative performance.**\n\nMo is a strict functional language where you write clean, compositional code and the compiler generates efficient imperative output. No ownership annotations. No garbage collector.\n\n\u003e **Paper:** [Mo: Pure Functional Code, Imperative Performance](docs/paper/mo_abstract.pdf)\n\n---\n\n## The result\n\nOn five non-pipeline benchmarks, Mo runs at roughly Zig-comparable time (~1x) with lower measured peak RSS.\n\n| Benchmark | Pattern | vs Zig (Time) | vs Zig (Memory) | Note |\n|-----------|---------|:---:|:---:|------|\n| Edit Distance | 2D dynamic programming | ~1x | **0.97x** | Same 2-row algorithm both sides |\n| Graph BFS | Visited set, queue | ~1x | **0.82x** | Zig baseline being strengthened |\n| Red-Black Tree | Balanced tree, rebalancing | ~1x | **0.90x** | Mo delegates to a native runtime tree |\n| LRU Cache | HashMap + linked list | ~1x | **0.92x** | Same delegation; eviction semantics differ slightly |\n| Regex NFA | State machine simulation | — | — | Under repair: current Mo matcher lacks epsilon closure |\n\nThese aren't pipelines. They're graph traversals, dynamic programming, pointer-heavy trees, coordinated data structures, and state machines --- the cases that have historically been hard for functional languages.\n\n**Caveats we're actively addressing:** the two sides currently use different allocators (malloc vs Zig's GPA), Mo-emitted code does not yet free memory (which flatters peak RSS for short-lived processes), and the benchmark runner does not yet assert output equality. See [docs/guide/generalization_benchmarks.md](docs/guide/generalization_benchmarks.md) for methodology. The strongest measured result is Mo-vs-Mo: the compiler's swap-buffer and hoisting passes automatically reduce per-iteration allocation by up to 752x on naively written DP folds.\n\n---\n\n## Quick start\n\n**Prerequisites:** OCaml (for the compiler), Zig 0.15+ (for the runtime)\n\n```bash\n# Build the compiler\n./src/compiler/build.sh\n\n# Compile and run an example\n./src/compiler/moc examples/fib.mo\nzig run examples/fib.zig\n```\n\n---\n\n## What it looks like\n\n```ml\n-- Fibonacci\nletrec fib = \\n -\u003e\n  if lt n 2 then n\n  else add (fib (sub n 1)) (fib (sub n 2))\nin fib 35\n```\n\n```ml\n-- Pipeline fusion: compiles to a single loop, zero intermediate arrays\nlet sum_doubled = \\xs -\u003e\n  fold (\\acc x -\u003e add acc x) 0 (map (\\x -\u003e mul x 2) xs)\nin\nsum_doubled (collect (range 0 10))\n```\n\n```ml\n-- O(log n) red-black tree with pure functional semantics\nlet tree = treemap_put tree key value in\nlet (tree, result) = treemap_get tree key in\n```\n\n```ml\n-- Edit distance: compiler detects swap-buffer pattern,\n-- allocates two buffers upfront instead of per-iteration\nlet result = fold (\\(prev_row, curr_row) i -\u003e\n  let new_row = compute_dp_row prev_row curr_row i in\n  (curr_row, new_row)\n) (row0, row1) (range 0 num_rows)\n```\n\n---\n\n## How it works\n\nThree mechanisms close the gap between functional semantics and imperative efficiency:\n\n**1. Linearity inference.** The compiler infers when values are used exactly once, enabling in-place mutation --- without user-written ownership annotations. Unlike Rust, where developers explicitly manage lifetimes, Mo infers linearity from usage. The current analysis has known soundness gaps that are being closed; a runtime uniqueness check with copy fallback is planned as the safety net.\n\n**2. Stateful pattern fusion.** Common patterns (swap-buffer, buffer hoisting, prefix slices) are detected and optimized automatically. The compiler extends fusion beyond pipelines to stateful folds.\n\n**3. Opaque linear handles.** When algorithmic complexity matters (O(log n) trees, O(1) caches), handles provide efficient mutable data structures with pure functional semantics.\n\n```\n Pure Functional Code\n fold, map, filter, update_inplace, treemap_*, lru_*, ...\n                     |\n                     v\n              OCaml Compiler\n       Analysis + Optimization Engine\n  (linearity inference, pattern fusion, stream fusion;\n       type checking currently via the Zig backend)\n                     |\n                     v\n            Generated Zig Code\n  In-place mutation, efficient data structures, zero-copy\n```\n\n---\n\n## Project structure\n\n```\nmo/\n  src/\n    compiler/            # OCaml compiler (lexer, parser, analysis, optimizer, codegen)\n    runtime/             # Zig runtime (allocators, arrays, streams)\n  lib/\n    std/                 # Standard library\n  examples/              # Example programs (.mo files)\n  docs/\n    paper/               # Research paper (LaTeX + PDF)\n    guide/               # Language guide, spec, optimization docs\n```\n\n---\n\n## Documentation\n\n| Document | What it covers |\n|----------|----------------|\n| [Paper (PDF)](docs/paper/mo_abstract.pdf) | Research paper with benchmarks and design |\n| [Language Guide](docs/guide/language_guide.md) | Syntax, semantics, and practical reference |\n| [Language Spec](docs/guide/spec.md) | Full specification |\n| [Opaque Linear Handles](docs/guide/opaque_linear_handles.md) | HashMap, TreeMap, LRU, Deque APIs |\n| [Stateful Pattern Fusion](docs/guide/stateful_pattern_fusion.md) | Compiler optimization passes |\n| [Benchmarks](docs/guide/generalization_benchmarks.md) | Methodology and results |\n\n---\n\n## Status\n\nMo is an early-stage research prototype exploring whether pure functional code can achieve systems-level performance. The compiler runs and the code is here to try; the benchmark suite and the linearity analysis are under active repair, and claims above should be read with the stated caveats.\n\nWhat exists:\n- Working compiler (OCaml) targeting Zig, fast happy-path builds\n- Stream fusion, linearity heuristics, stateful pattern fusion (swap-buffer and hoisting passes)\n- Opaque linear handles (HashMap, TreeMap, LRU, Deque) backed by native runtime implementations\n- Examples and a small standard library\n\nWhat's next (in order):\n- Benchmark suite repair (regex epsilon closure, stronger Zig baselines, matched allocators, output-equality checks)\n- A sound, gated linearity analysis with a runtime uniqueness fallback\n- A real type checker and name resolution in the Mo frontend\n- Formalization of the rolling-buffer inference (the core research contribution)\n\n---\n\n## License\n\n- Code (compiler, runtime, standard library, examples): [MIT](LICENSE) — No Way Labs\n- Paper (`docs/paper/`): [CC BY 4.0](docs/paper/LICENSE)\n\n---\n\n*Mo: where functional programming meets systems performance.*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fno-way-labs%2Fmo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fno-way-labs%2Fmo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fno-way-labs%2Fmo/lists"}