An intent-first, constrained general-purpose functional language designed for clear meaning and low token usage. It favors pure functions, explicit data flow, and no hidden state.
Goal: help LLMs generate minimal detail and clear computational intent, with strict constraints and compile/eval layers ensuring deterministic semantics.
For the full language notes, see AGENTS.md.
This project is built to address three practical pain points when using LLMs for code generation:
- unclear expression of intent (high review cost, overgrown scaffolding),
- hallucinated or noisy implementation details (diluted intent, extra context),
- inflated token usage and higher cost from the above.
IF Lang is intended as a pre‑implementation logic layer: LLMs first generate a small, precise POC or draft in IF Lang for human review, then either a human or an LLM produces the concrete implementation in the target language.
- Intent-first: pipelines (
x |> f(a)) read like steps. - Pure by default: no implicit mutation or IO.
- Explicit externs: host-provided functions must be declared.
- Strong constraints: parameter usage order must match signature order.
Full syntax reference: SYNTAX.md.
This repo includes a Codex skill for IF Lang: SKILL.md. Use it to guide IF Lang edits, enforce constraints (externs, parameter order, pipeline style), and keep logic in IF Lang with minimal extras.
- BST Top-K
- IF: examples/bst_topk.if
- Rust extra: examples/bst_topk_extra.rs
- Python extra: examples/bst_topk_extra.py
- Mini web
- IF: examples/mini_web.if
- Rust extra: examples/mini_web_extra.rs
- Python extra: examples/mini_web_extra.py
- Mini SQL
- IF: examples/mini_sql.if
- Rust extra: examples/mini_sql_extra.rs
- Python extra: examples/mini_sql_extra.py
One-line scripts (requires cargo install if_lang) — Python extra by default:
./scripts/run_bst_topk.sh
./scripts/run_mini_web.sh
./scripts/run_mini_sql.sh
Tip: pass rust as the optional parameter to run the Rust extra(e.g. ./scripts/run_mini_sql.sh rust).
Run directly with extras:
# Python extra (.py)
if_lang extra examples/bst_topk_extra.py examples/bst_topk.if
# Rust extra (.rs, compiled to dylib on the fly)
if_lang extra examples/bst_topk_extra.rs examples/bst_topk.if
# Rust extra (prebuilt dylib)
if_lang extra path/to/libbst_topk_extra.so examples/bst_topk.if
Format IF source (rustfmt-style UX):
# Format in-place
if_lang fmt examples/bst_topk.if
# Check formatting (non-zero exit if different)
if_lang fmt --check examples/bst_topk.if
# Format from stdin to stdout
cat examples/bst_topk.if | if_lang fmt -
- Constructors are Uppercase and use field syntax:
Node { value, left, right } matchsupports field destructuring and comparison patterns (e.g.>= 80)- Extern functions must be declared with an
explain { ... }block and registered at runtime
- VS Code extension (syntax highlighting + diagnostics):
editors/vscode
- Build or install the CLI so
if_langis available on your PATH (e.g.cargo install if_lang). - In VS Code, run “Developer: Install Extension from Location...” and select
editors/vscode. - Open a
.iffile. Diagnostics run on save by default.
Settings:
iflang.cliPath: Path to theif_langCLI (default:if_lang).iflang.diagnosticsMode:onSave(default),onType, oroff.iflang.diagnosticsDebounceMs: Debounce time (ms) foronType.
Features:
- Syntax highlighting.
- Diagnostics via
if_lang check. - Go to Definition / Find References (workspace-wide, best-effort).