fx-lang is an experimental language for exploring scoped effects, named scopes, and coeffects.
The repository contains a Rust implementation of the parser, formatter, type checker, JavaScript compiler path, CLI, and language server experiments. It is research code first: the examples are organized by implementation phase, and some language features are intentionally narrower than the long-term design.
This example combines the main ideas:
Stateis a scoped effect family.Counteris a named scope for oneState Intcell.within Counterlets operations omit their explicit scope argument.given { clock: Clock }is a coeffect: the function needs contextual data, but it is not an ordinary parameter.
Copyable source
export scoped effect State s a
get() : a
put(value: a) : Unit
export type Clock = { now: Text }
scope Counter with <State Int>
increment-and-label() : Text with <State Counter Int> given { clock: Clock }
within Counter
n = get()
put(n + 1)
clock.now ++ " count=" ++ show(n + 1)
The scope name distinguishes one state cell from another at the type level,
while given tracks required context separately from ordinary function
arguments and effect rows.
Check the promoted Phase 5 examples:
cargo run -q -p fx-cli -- check examples/phase-5The full examples tree also contains intentional diagnostics fixtures.
Format sources:
cargo run -q -p fx-cli -- fmt --check examplesCompile the currently supported JavaScript subset:
cargo run -q -p fx-cli -- compile --target js --out-dir /tmp/fxl examples/phase-5
node /tmp/fxl/with-clock.mjscrates/fx-syntax: lexer, parser, AST, diagnostics, and formattercrates/fx-core: module loading, resolution, and type checkingcrates/fx-compiler: lowering and JavaScript emissioncrates/fx-cli: command-line interfacecrates/fx-lsp: language server prototypeexamples: phase-oriented language examplesnotes: design notes, implementation plans, and phase learnings
fx-lang is pre-release and changing quickly. It is useful for experimenting with typed effect systems, named effect scopes, contextual requirements, and compiler/runtime design, but it is not intended for production use.