Code Generation Overview
Paradox generates idiomatic code from .dox source files in fifteen target languages. Every target produces type definitions, validators, and (where applicable) serialization code.
How It Works
-
Parse
.doxfiles into the internal AST -
Type-check and validate (including SMT verification)
-
Traverse the checked AST to emit target-specific code
-
Write output files to the working directory
Universal Type Mapping
| Paradox | TypeScript | Haskell | Rust | Python | C++ | Elixir | OCaml | Scala | C# | Java | SQL | Bash | Nix |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
— |
|
|
|
|
|
|
|
|
|
|
|
|
|
— |
|
|
|
|
|
|
|
|
|
|
|
|
|
— |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
branded type |
|
|
|
|
struct |
abstract type |
|
|
|
column + CHECK |
alias |
|
| OCaml and Nix represent sets as sorted lists (Nix deduplicates on cast). Bash has no distinct set type; sets are stored as arrays. SQL does not support collection-typed columns. |
Targets
| Target | Extension | Notes |
|---|---|---|
|
Interfaces, branded wraps, source maps |
|
|
Data types, newtypes, Aeson JSON |
|
|
Structs, enums, serde |
|
|
Dataclasses |
|
|
Structs, typespecs |
|
|
C++23, nlohmann/json |
|
|
Records, variants, Yojson |
|
|
Scala 3 case classes |
|
|
C# 10 records, nullable types |
|
|
Records, sealed interfaces, pattern matching |
|
|
SQLite and PostgreSQL DDL |
|
|
Shell constructors and validators |
|
|
Attribute sets, builtins validation |
|
|
Constant serialization |
|
|
Typed AST output |
Framework Generators
Beyond per-language code generation, Paradox includes higher-level generators that produce complete server and client scaffolds from URI specifications:
| Generator | Description |
|---|---|
Express.js server with typed handler stubs |
|
Haskell Servant API type from URI declarations |
|
Rust/WASM async HTTP client via gloo-net |
|
Full-stack Express + PostgreSQL CRUD server with auth and HTML views |
State Machine Generation
When a specification contains Machine constants, Paradox automatically extracts them and generates standalone state machine modules alongside the normal type codegen. Each generated module includes a state enum, event enum, context struct, and a transition function.
State machines are verified at compile time for determinism, reachability, deadlock freedom, complete event coverage, and liveness before code generation proceeds.
State machine code generation supports eleven targets: TypeScript, Haskell, Rust, Python, C++, Elixir, Scala, OCaml, Nix, Bash, and C#.
See State Machines for the full reference.
Output Conventions
-
Each
.doxsource file produces one output file per target -
Files include a "do not edit by hand" header
-
Module naming follows the source file name (e.g.,
product.dox→Dox.Productin Haskell) -
Validators are always generated, even when no
validblock exists (they pass all values through)