Many features were documented as "missing" or "planned" but are actually working: generics, string interpolation, File/HTTP/Random/Time effects, JSON parsing, module system, and JIT CLI integration. Updated IMPLEMENTATION_PLAN.md, OVERVIEW.md with accurate status. Added ROADMAP.md (use-case-targeted) and LANGUAGE_COMPARISON.md. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
11 KiB
Lux Language Implementation Plan
Current Status Summary
What's Working (150+ 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, postRandom- 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, etc.) - Property parsing and storage in AST
- Pure function verification (no effects allowed)
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/outputexamples/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: ⚠️ Partial
What's Working:
- Source code context with line/column numbers
- Caret pointing to error location
- Color-coded error output
What's Missing:
- Type diff display for mismatches
- "Did you mean?" suggestions
- Error recovery in parser
Implementation Steps:
- Add Levenshtein distance for suggestions
- Implement error recovery in parser
- Add 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: ⚠️ Partial - Several working, some missing
Working Effects:
Console- print, readLine, readIntFile- read, write, exists, delete, listDir, createDirHttp- get, postRandom- int, float, range, bool, elementTime- now, sleep
Missing Effects:
State<S>- get/put state (generic over state type)Reader<R>- read-only environmentFail- early returns/exceptionsAsync- async/await
Implementation Steps:
- Add generic effect support (
State<S>) - Implement
Failfor error handling - Add async/await pattern
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: Parser supports @v1 syntax but runtime doesn't use it.
What's Missing:
- Version tracking in type system
- Migration function generation
- Compatibility checking
- Codec generation
Implementation Steps:
- Track version in type representation
- Implement migration chain resolution
- Add compatibility rules to type checker
- Generate serialization code
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
What's Needed:
- Package registry
- Dependency resolution
- Version management
- Build system integration
6.2 Standard Library
What's Needed:
- Collections (Map, Set, Array)
- String utilities
- Math functions
- File I/O
- Network I/O
- JSON/YAML parsing
6.3 Debugger
What's Needed:
- Breakpoints
- Step execution
- Variable inspection
- Stack traces
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 - Termination checking
- Idempotent verification - Pattern-based analysis
- Where clause enforcement - Constraint checking
Phase 5: Schema Evolution (Data)
- Type system version tracking
- Auto-migration generation
- Version-aware serialization
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 | ⚠️ Parsing | ❌ | ❌ | ❌ | ❌ |
| Behavioral Types | ⚠️ Parsing | ❌ | ❌ | ❌ | ❌ |
| 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 (planned) - Type-safe data migrations built into the language
- Behavioral types (planned) - Compile-time verification of properties like purity and totality
- Developer experience - Elm-style errors, REPL, LSP support
The combination of these features makes Lux particularly suited for:
- Building reliable backend services
- Applications with complex state management
- Systems requiring careful versioning and migration
- Projects where testing and verification are critical