- Add String.fromChar, chars, substring, toUpper, toLower, replace, startsWith, endsWith, join to C backend - Fix record type alias unification by adding expand_type_alias and unify_with_env functions - Update docs to reflect current implementation status - Clean up outdated roadmap items and fix inconsistencies - Add comprehensive language comparison document Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
12 KiB
Lux Language Implementation Plan
Current Status Summary
What's Working (222 tests passing)
Core Language:
- Lexer and parser for core syntax
- AST representation
- Type checker with Hindley-Milner inference
- Interpreter with REPL
- Tail call optimization (TCO)
- Pattern matching with exhaustiveness checking
- Algebraic data types (ADTs) with constructors
- Records and tuples
- Higher-order functions and closures
- Pipe operator (
|>) - Documentation comments
- Generic type parameters (
fn map<T, U>,type List<T>) - String interpolation (
"Hello {name}!") - Escape sequences (
\n,\t,\",\{,\})
Effect System:
- Effect declarations
- Effect signatures on functions (
with {Effect}) - Handler definitions
run ... withsyntax- Effect inference within function bodies
- Effect subset checking (pure functions callable in effectful contexts)
Built-in Effects:
Console- print, readLine, readIntFile- read, write, exists, delete, listDir, createDirHttp- get, post, put, delete (HTTP client)HttpServer- listen, accept, respond, respondWithHeaders, stop (HTTP server)Random- int, float, range, bool, elementTime- now, sleep
Type Classes:
- Trait declarations
- Implementation blocks
- Basic trait method dispatch
Behavioral Properties:
- Property declarations (
is pure,is idempotent,is total,is deterministic,is commutative) - Property parsing and storage in AST
- Pure function verification (no effects allowed)
- Deterministic verification (no Random/Time effects)
- Commutative verification (operator-based analysis)
- Idempotent verification (pattern-based analysis)
- Total verification (structural recursion, termination checking)
Module System:
- Import/export with
pubvisibility - Aliased imports (
import foo as bar) - Selective imports (
import foo.{a, b}) - Wildcard imports (
import foo.*) - Circular dependency detection
- Transitive imports
JIT Compiler (Cranelift):
- Integer arithmetic and comparisons
- Conditionals, let bindings, blocks
- Function calls including recursion
- ~160x speedup over interpreter for numeric code
- CLI integration via
lux compile <file>
Standard Library:
- String operations (substring, length, split, trim, etc.)
- List operations (map, filter, fold, etc.)
- JSON parsing and serialization
- Math functions
Tooling:
- REPL with history and autocomplete
- LSP server (diagnostics, hover, completions)
- Watch mode for auto-recompilation
- Source-context error messages
Example Programs Working
hello.lux- Basic effect usagefactorial.lux- Recursioneffects.lux- Custom effects and handlersdatatypes.lux- ADTs and pattern matchingfunctional.lux- Higher-order functionstraits.lux- Type classesbehavioral.lux- Behavioral propertiestailcall.lux- Tail call optimizationstatemachine.lux- State machines with ADTspipelines.lux- Pipe operatorgenerics.lux- Generic type parametersjson.lux- JSON parsing and serializationjit_test.lux- JIT compilation demoguessing_game.lux- Console input/outputhttp_server.lux- HTTP server with routingexamples/modules/main.lux- Module importsexamples/modules/main_selective.lux- Selective importsexamples/modules/main_wildcard.lux- Wildcard imports
Missing Features Analysis
Priority 1: Critical Missing Features
1.1 Generic Type Parameters
Status: ✅ Complete
Generic type parameters are fully working:
- Type parameter declarations in type definitions (
type List<T> = ...) - Generic function parameters (
fn map<T, U>(f: fn(T): U, list: List<T>): List<U>) - Type application and instantiation
- See
examples/generics.luxfor working examples
Still Missing (nice-to-have):
- Type parameter constraints (
where T: Eq)
1.2 String Interpolation
Status: ✅ Complete
String interpolation is fully working:
"Hello, {name}!"syntax- Nested expressions:
"Result: {1 + 2}" - Escape sequences:
\{,\},\n,\t,\",\\
1.3 Better Error Messages
Status: ✅ Complete (Elm-quality)
What's Working:
- Source code context with line/column numbers
- Caret pointing to error location
- Color-coded error output
- Field suggestions for unknown fields
- Error categorization
- Improved hints
Nice-to-have (not critical):
- Error recovery in parser
- Type diff visualization
Priority 2: Effect System Completion
2.1 Effect Polymorphism
Status: Not implemented.
What's Missing:
- Functions generic over their effects
- Effect variables in type signatures
- Effect constraints
Example syntax:
fn withRetry<E>(action: fn(): T with E, attempts: Int): T with E = ...
Implementation Steps:
- Add effect variables to effect representation
- Implement effect unification with variables
- Support effect quantification in type schemes
2.2 Built-in Effects
Status: ✅ Core effects complete
Working Effects:
Console- print, readLine, readIntFile- read, write, exists, delete, listDir, createDirHttp- get, post, put, delete (HTTP client)HttpServer- listen, accept, respond, respondWithHeaders, stopRandom- int, float, range, bool, elementTime- now, sleepState- get, put (built-in)Reader- ask (built-in)
Missing Effects (nice-to-have):
Async- async/await pattern- Generic effect parameters (
State<S>)
2.3 Resumable Handlers
Status: Handlers exist but may not support continuation resumption.
What's Missing:
resumekeyword to continue computation- Multi-shot continuations
- Proper effect handler semantics
Priority 3: Schema Evolution
3.1 Versioned Types
Status: ✅ Type system integration complete
What's Working:
- Version annotations preserved in type system (
Int @v1,User @v2) - Version mismatch detection at compile time
- Version constraints:
@v1(exact),@v2+(at least),@latest(any) - Versioned type declarations tracked
- Migration bodies stored for future execution
What's Working:
- Auto-migration generation
Still Missing (nice-to-have):
- Version-aware serialization/codecs
Priority 4: Module System
4.1 Complete Import/Export
Status: ✅ Complete.
The module system is fully functional with:
import foo/bar- basic importsimport foo/bar as alias- aliased importsimport foo.{a, b}- selective importsimport foo.*- wildcard importspub fnvisibility for exports- Circular dependency detection (tested)
- Module caching
- Transitive imports
- Type checking across modules
Still Missing (nice-to-have):
- Re-exports (
pub import) - Package manifest (
package.lux)
Priority 5: Code Generation
5.1 Compile to Target
Status: ⚠️ Partial - JIT works for numeric code
What's Working:
src/compiler.rs- Cranelift JIT compiler (539 lines)- Integer arithmetic, comparisons, boolean ops
- Conditionals, let bindings, function calls, blocks
- Recursive functions (fib(30) compiles and runs)
- CLI integration:
lux compile <file> [--benchmark] - ~160x speedup over interpreter for numeric code
What's Missing in JIT:
- Strings, floats, lists, records, tuples
- Pattern matching, ADTs
- Effects and handlers
Target Options for Full Compilation:
- WASM - Best for web and portable deployment
- JavaScript - Easiest web integration
- Extend Cranelift - Build on existing JIT
Implementation Steps:
Expose JIT via CLI command✅ Done- Add support for more types (strings, lists, etc.)
- Compile pattern matching
- Handle effects (CPS transform or evidence passing)
Priority 6: Tooling
6.1 Package Manager
Status: ✅ Complete
What's Working:
lux pkg init- Initialize project with lux.tomllux pkg add/remove- Manage dependencieslux pkg install- Install from lux.toml- Git and local path dependencies
- Package registry (
lux registry) - CLI commands (search, publish)
Still Missing (nice-to-have):
- Version conflict resolution
6.2 Standard Library
Status: ✅ Complete
What's Working:
- String operations (substring, length, split, trim, etc.)
- List operations (map, filter, fold, etc.)
- Option and Result operations
- Math functions
- JSON parsing and serialization
Still Missing (nice-to-have):
- Collections (Map, Set)
- YAML parsing
6.3 Debugger
Status: ✅ Basic
What's Working:
- Basic debugger
Nice-to-have:
- Breakpoints
- Step execution
- Variable inspection
Recommended Implementation Order
Phase 1: Language Completeness (Essential)
Generic type parameters✅ DoneString interpolation✅ Done- Better error messages - Elm-quality suggestions
Phase 2: Effect System Maturity
Built-in effects (Console, File, Http, Random, Time)✅ Done- Effect polymorphism - Generic effect parameters
- Fail effect - Proper error handling pattern
- Resumable handlers - Multi-shot continuations
Phase 3: Production Readiness
Complete module system✅ DoneStandard library basics✅ Done (String, List, JSON)- Package manager - Dependency resolution
- Full compilation - Extend JIT or add WASM/JS backend
Phase 4: Behavioral Types (Verification)
Total function verification✅ Done - Termination checkingIdempotent verification✅ Done - Pattern-based analysisDeterministic verification✅ Done - Effect-based analysisCommutative verification✅ Done - Operator analysisWhere clause enforcement✅ Done - Property constraints
Phase 5: Schema Evolution (Data)
Type system version tracking✅ DoneVersion mismatch detection✅ Done- Auto-migration generation - Generate migration code
- Version-aware serialization - Codecs
Phase 6: Advanced Features
- Refinement types - SMT solver integration
- Async/await effect
- Stream processing
Technical Debt
Known Issues Fixed During Testing
- ✅ String concatenation with
+operator wasn't type-checked correctly - ✅ ADT constructors weren't registered in type environment
- ✅ ADT constructors weren't registered in interpreter environment
- ✅ Handlers weren't accessible as values
- ✅ Effect checking was too strict (required exact match instead of subset)
- ✅
totalkeyword conflicts with variable names in examples
Remaining Technical Debt
- Dead code in diagnostics, modules, parser (suppressed with
#![allow(dead_code)]) - Some test utilities not fully utilized
- LSP server basic but could be expanded
- Error recovery in parser incomplete
Feature Comparison with Other Languages
| Feature | Lux | Koka | Haskell | Rust | TypeScript |
|---|---|---|---|---|---|
| Algebraic Effects | ✅ | ✅ | Via libs | ❌ | ❌ |
| Type Inference | ✅ | ✅ | ✅ | Partial | Partial |
| ADTs | ✅ | ✅ | ✅ | ✅ | Via unions |
| Pattern Matching | ✅ | ✅ | ✅ | ✅ | Limited |
| Generics | ✅ | ✅ | ✅ | ✅ | ✅ |
| Type Classes | Basic | ✅ | ✅ | ✅ | ❌ |
| String Interpolation | ✅ | ✅ | ❌ | ❌ | ✅ |
| Effect Polymorphism | ❌ | ✅ | Via mtl | N/A | N/A |
| Schema Evolution | ✅ | ❌ | ❌ | ❌ | ❌ |
| Behavioral Types | ✅ | ❌ | ❌ | ❌ | ❌ |
| HTTP Server | ✅ | ❌ | Via libs | Via libs | Via libs |
| Refinement Types | Planned | ❌ | Via LH | ❌ | ❌ |
| Tail Call Opt | ✅ | ✅ | ✅ | Limited | ❌ |
| JIT Compilation | ⚠️ Numeric | ✅ | ✅ | N/A | N/A |
| REPL | ✅ | ✅ | ✅ | Limited | ✅ |
| LSP | Basic | ✅ | ✅ | ✅ | ✅ |
Unique Value Proposition
Lux differentiates itself through:
- First-class algebraic effects - Making side effects explicit, testable, and composable
- Schema evolution - Type-safe version tracking with compile-time mismatch detection
- Behavioral types - Compile-time verification of purity, totality, determinism, idempotency
- Built-in HTTP server - Effect-tracked web servers without external frameworks
- Developer experience - Elm-style errors, REPL, LSP support
The combination of these features makes Lux particularly suited for:
- Building reliable backend services with explicit effect tracking
- Applications with complex state management
- Systems requiring careful versioning and migration
- Projects where testing and verification are critical
- Educational use for learning algebraic effects