a functional & reactive language for the full stack web
Find a file
2026-05-24 23:54:31 -04:00
docs refactor: Result type and introduce type parameter defaults 2026-05-24 15:35:15 -04:00
editor/vscode feat(lsp): basic lsp with type information on hover 2026-05-18 19:02:42 -04:00
examples feat: add support for computed-key record literals and enhance related parsing and type inference 2026-05-24 23:54:31 -04:00
src feat: add support for computed-key record literals and enhance related parsing and type inference 2026-05-24 23:54:31 -04:00
stdlib feat: add support for 'new' expression in AST, parser, and type inference 2026-05-24 22:35:42 -04:00
tests feat: add support for computed-key record literals and enhance related parsing and type inference 2026-05-24 23:54:31 -04:00
.gitignore initial commit. basic lexing 2026-05-12 02:11:20 -04:00
bun.lock feat(lsp): basic lsp with type information on hover 2026-05-18 19:02:42 -04:00
mise.toml feat: implement general union types and normalization in type system 2026-05-24 15:59:59 -04:00
package.json feat(lsp): basic lsp with type information on hover 2026-05-18 19:02:42 -04:00
README.md docs: update readme 2026-05-20 18:32:52 -04:00
tsconfig.json initial commit. basic lexing 2026-05-12 02:11:20 -04:00

catena

A functional language that compiles to TypeScript and targets Bun.

Features

Types and bindings

  • const bindings with optional type annotations
  • Full Hindley-Milner type inference — annotations are optional everywhere
  • Type aliases (alias UserId = String, alias Pair<A, B> = (A, B))
  • Algebraic data types (type Option<T> = None | Some(T))
  • Record types ({ x: Int, y: Int }), tuple types ((Int, String))
  • Function types (Int -> Int -> Bool)

Functions

  • Named functions: fn add(x: Int, y: Int): Int -> x + y
  • Multi-parameter functions with automatic currying
  • Anonymous lambdas: fn x -> x + 1, fn (x, y) -> x + y
  • Nullary functions: fn greet() -> "hello"
  • Paren-free application: f x or f(x) — both work
  • Pipe operator: x ~> f ~> g (left-to-right application)
  • Compose operators: f >> g (left-to-right), f << g (right-to-left)

Data structures

  • Record literals: { name: "Alice", age: 30 }
  • Record spread: { ...base, age: 31 }
  • Deep path update: { ...user, address.city: "LA" }
  • Tuples: (1, "hello", true) with static index access pair[0]
  • Pattern matching on all of the above

Pattern matching

  • match expressions with exhaustiveness checking
  • Literal, wildcard, variable-binding, constructor, record, tuple patterns
  • Or-patterns: 1 | 2 | 3 -> "small"
  • As-patterns: p@(x, y) -> ...
  • Optional match-arm guards: x if x > 0 -> ...
  • Unreachable-arm warnings

FFI / interop

  • Namespace imports: use 'node:fs' as Fs
  • Typed named imports with compile-time curry wrappers: use './lib'.{ fn: A -> B }
  • Untyped named imports with runtime arity detection
  • @raw"..." — inline TypeScript in type or expression position
  • as casts: x as Float, x as @raw"NodeJS.ProcessEnv"

Prelude (auto-included in every program)

  • Option<T>, Result<E, T>, Either<L, R>, List<T>
  • Function combinators: id, const_, flip
  • Tuple helpers: fst, snd, swap
  • Option and Result combinators: map_option, and_then_option, map_result, and_then_result, etc.
  • print built-in

Setup

bun install

Usage

Compile and run:

bun run catena examples/hello.ctn --run

Compile only (produces a .ts file next to the source):

bun run catena examples/factorial.ctn
# → examples/factorial.ts

Examples

See examples/:

File What it shows
hello.ctn Hello, world
factorial.ctn Recursion
fibonacci.ctn Mutual recursion
functions.ctn Multi-arg functions, lambdas
records.ctn Records, spreads, deep path update
tuples.ctn Tuples and indexing
pattern-matching.ctn Match expressions and patterns
functional.ctn Pipe and compose operators
raw_and_as.ctn @raw escapes and as casts
showcase.ctn Full feature tour: ADTs, FFI, pattern matching

Development

Run tests:

bun test

The compiler is a single linear pipeline:

Module Role
src/lexer.ts Source string → tokens
src/parser.ts Tokens → CST (Chevrotain grammar)
src/cst-to-ast.ts CST → typed AST
src/typechecker.ts Hindley-Milner inference + exhaustiveness checking
src/backends/typescript.ts AST → TypeScript
src/codegen.ts Backend registry and dispatch
src/compile.ts Wires pipeline together
src/cli.ts Command-line entry point
stdlib/src/prelude.ctn Auto-included standard types and combinators