🦖 Rex
Rex (short for Rush Expressions) is a strongly-typed,
pure, implicitly parallel functional programming language built to be an
excellent target for LLM-generated programs, with a focus on scientific
workflows and data analysis pipelines. At a high level, you write
transformations over lists, records, ADTs, and other values using familiar
functional building blocks like map, filter, folds, pattern matching, and
composition. The language is designed to make dataflow clear and predictable,
with types and pure expressions doing most of the heavy lifting.
Rex is designed first and foremost to be embedded inside Rust applications. In that model, your Rust program acts as the host runtime and injects native functions into Rex so scripts can orchestrate real work while staying in a concise, declarative style. This makes Rex a practical scripting layer for workflow-style systems where you want strong typing and explicit control at the host boundary.
Because Rex programs are pure and free of side effects in the language itself, the runtime can safely execute host-provided async functions in parallel when it is valid to do so. In practice, that means users can write straightforward functional code and still benefit from concurrency without directly managing threads, locks, or low-level async orchestration.
If you are using Rex as a code-generation target, read LLM Guidance early. It captures syntax pitfalls and validation workflow that reduce iteration time.
Example
let
values = [3, 12, 7, 20, 15, 4],
selected = filter (\n -> n >= 10) values,
adjusted = map (\n -> n - 2) selected,
total = foldl (\acc n -> acc + n) 0 adjusted
in
(values, selected, adjusted, total)
Try it yourself in the interactive browser-based playground
Rex as a target for LLMs
Rex is the world’s first parallel functional language explicitly designed to be a useful target for LLMs. Its strong static type system gives rapid, high-signal feedback on generated programs, so both users and models can quickly identify mismatches and converge on correct code.
That typechecking loop works especially well with Rex’s functional, expression-oriented style. Because programs are written as pure data transformations, LLM-generated code tends to be easier to inspect, reason about, and refine than imperative scripts with hidden state or side effects.
Together, these properties make Rex a strong fit for LLM-generated data analysis pipelines and scientific workflows. Models can generate high-level orchestration in Rex, while host-provided Rust functions handle domain-specific execution, giving a clean split between deterministic workflow logic and host capabilities.
Documentation
Crates
This repo is a Cargo workspace. The key crates are:
rexlang-lexer: tokenization (+ spans)rexlang-parser: parser producing aProgram { decls, expr }rexlang-typesystem: Hindley–Milner type inference + type classes + ADTsrexlang-engine: runtime evaluator + native-function injection, backed byrexlang-typesystemrexlang-proc-macro:#[derive(Rex)]for bridging Rust types ↔ Rex ADTs/valuesrexlang-cli: CLI crate providing therexbinary (cargo run -p rexlang-cli -- ...)rexlang-fuzz: stdin-driven fuzz harness binariesrexlang-util: small shared helpers (e.g. library hashing, bundled stdlib sources)rexlang-lsp/rexlang-vscode: language tooling (LSP + VS Code extension)
CLI
Run a file:
Run the advanced library import example:
Run inline code:
Other useful flags:
--emit-ast: print parsed AST as JSON and exit--emit-type(alias:--type): print inferred type as JSON and exit--stdin: read a program from stdin--stack-size-mb: control the runner thread stack size--max-nesting: cap syntactic nesting depth during parsing--no-max-nesting: disable the parsing nesting cap--gas: total gas budget for parse/type/eval--no-gas: disable gas metering
Standard Library (Prelude)
Rex ships with a prelude that provides core functions, types, and type classes used throughout the language (for example mapping, filtering, folds, numeric operations, equality/ordering, and container abstractions).
The prelude surface definitions and type-class wiring live primarily in:
rexlang-typesystem/src/prelude_typeclasses.rexrexlang-typesystem/src/prelude.rsrexlang-engine/src/prelude.rs
For full details and usage patterns, see the docs:
Made with ❤️ by QDX