Skip to main content

Getting Started with AILANG

For AI Agents: Quick Integration

AILANG is designed for AI-assisted development. To integrate AILANG into your AI coding agent:

Step 1: Install AILANG

# macOS (Apple Silicon)
curl -L https://github.com/sunholo-data/ailang/releases/latest/download/ailang-darwin-arm64.tar.gz | tar -xz
sudo mv ailang /usr/local/bin/

# macOS (Intel)
curl -L https://github.com/sunholo-data/ailang/releases/latest/download/ailang-darwin-amd64.tar.gz | tar -xz
sudo mv ailang /usr/local/bin/

# Linux
curl -L https://github.com/sunholo-data/ailang/releases/latest/download/ailang-linux-amd64.tar.gz | tar -xz
sudo mv ailang /usr/local/bin/

# Verify
ailang --version

Step 2: Get the AILANG Teaching Prompt

Use the CLI to get the current syntax guide for your AI agent:

# Display the active teaching prompt
ailang prompt

# Save to a file
ailang prompt > ailang-syntax.md

# List all available versions
ailang prompt --list

This prompt teaches AI models:

  • Correct AILANG syntax (not Python/Rust/JavaScript)
  • Pure functional programming with recursion
  • Module system with effects (IO, FS, Clock, Net)
  • Record updates, pattern matching, ADTs
  • Auto-imported std/prelude (no manual imports for comparisons)

Include the prompt output in your AI agent's system prompt or context. You can also browse prompts on the website.

Step 3: Test AI Code Generation

Ask your AI agent to write AILANG code:

Using AILANG, write a program that reads a file and counts the number of lines.

[Paste output from: ailang prompt]

Expected output:

module benchmark/solution

import std/io (println)
import std/fs (readFile)

export func countLines(content: string) -> int {
-- Implementation using recursion
...
}

export func main() -> () ! {IO, FS} {
let content = readFile("data.txt");
println("Lines: " ++ show(countLines(content)))
}

Step 4: Run AI-Generated Code

ailang run --caps IO,FS --entry main solution.ail

AI Success Metrics

Latest benchmark results:

  • Check Benchmark Dashboard for current metrics
  • Best model: Claude Sonnet 4.5 (consistently highest success rates)
  • Results updated after each release

See AI Prompt Guide for detailed instructions.


For Human Developers: Manual Installation

Installation Options

Download pre-built binaries from the latest release.

From Source (For Development)

git clone https://github.com/sunholo/ailang.git
cd ailang
make install
ailang --version

Add Go bin to PATH:

# For zsh (macOS default)
echo 'export PATH="$HOME/go/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

Development workflow:

make quick-install    # Fast rebuild after changes
make test # Run tests
make verify-examples # Test example files

Quick Start

Hello World

examples/runnable/hello.ail
-- hello.ail - Simple hello world program
module examples/runnable/hello

-- Entry module with exported main function
-- Gets print prelude automatically (no import needed)
export func main() -> () ! {IO} =
print("Hello, AILANG!")

Run it:

ailang run --caps IO --entry main examples/runnable/hello.ail

Note: Flags must come BEFORE the filename when using ailang run.

Working with Values

-- values.ail
let name = "AILANG" in
let version = 0.0 in
print("Welcome to " ++ name ++ " v" ++ show(version))

Lambda Expressions

-- Lambda syntax with closures
let add = \x y. x + y in
let add5 = add(5) in -- Partial application
print("Result: " ++ show(add5(3))) -- Result: 8

-- Higher-order functions
let compose = \f g x. f(g(x)) in
let double = \x. x * 2 in
let inc = \x. x + 1 in
let doubleThenInc = compose(inc)(double) in
print("Composed: " ++ show(doubleThenInc(5))) -- Composed: 11

Using the REPL

Start the interactive REPL:

ailang repl

Try some expressions:

λ> 1 + 2
3 :: Int

λ> "Hello " ++ "World"
Hello World :: String

λ> let double = \x. x * 2 in double(21)
42 :: Int

λ> :type \x. x + x
\x. x + x :: ∀α. Num α ⇒ α → α

λ> :quit

Testing Your Code

NEW in v0.4.5: AILANG now supports inline tests for pure functions!

Writing Inline Tests

Add tests directly to your function definitions:

-- Single-parameter function
pure func factorial(n: int) -> int
tests [
(0, 1),
(1, 1),
(5, 120),
(10, 3628800)
]
{
if n <= 1 then 1 else n * factorial(n - 1)
}

-- Multi-parameter functions use tuple syntax
pure func add(x: int, y: int) -> int
tests [
((1, 2), 3),
((5, 7), 12)
]
{
x + y
}

Running Tests

ailang test examples/factorial.ail

Output:

→ Running tests in examples/factorial.ail

Test Results
Module: All Tests

Tests:
✓ factorial_test_1 (1.5ms)
✓ factorial_test_2 (800µs)
✓ factorial_test_3 (1.2ms)
✓ factorial_test_4 (900µs)

────────────────────────────────────────────
✓ All tests passed!

4 tests: 4 passed, 0 failed, 0 skipped (4.4ms)

Key features:

  • Tests run automatically on every test invocation
  • Fast execution (~10-60ms per file)
  • Works alongside export func main() - no conflicts!
  • Supports all data types: int, float, bool, string, lists, tuples

Limitations:

  • Only works for self-contained pure functions
  • Functions calling other user-defined functions not yet supported
  • Effect mocking not yet supported

See the Language Reference for complete documentation.

Working Examples

The following examples are confirmed to work with the current implementation:

Recursion:

  • examples/recursion_factorial.ail - Recursive factorial function
  • examples/recursion_fibonacci.ail - Fibonacci sequence
  • examples/recursion_quicksort.ail - Quicksort implementation
  • examples/recursion_mutual.ail - Mutual recursion (isEven/isOdd)

Records:

  • examples/micro_record_person.ail - Record literals and field access
  • examples/test_record_subsumption.ail - Record subsumption

Effects:

  • examples/test_effect_io.ail - IO effect examples
  • examples/test_effect_fs.ail - File system operations
  • examples/micro_clock_measure.ail - Clock effect (time, sleep)
  • examples/micro_net_fetch.ail - Net effect (HTTP GET)

Pattern Matching & ADTs:

  • examples/adt_simple.ail - Algebraic data types
  • examples/adt_option.ail - Option type with pattern matching
  • examples/guards_basic.ail - Pattern guards

Blocks:

  • examples/micro_block_if.ail - Block expressions with if
  • examples/micro_block_seq.ail - Sequential blocks
  • examples/block_recursion.ail - Recursion in blocks

See examples/STATUS.md for the complete list of 48+ working examples.

Next Steps