fix: make all example programs work correctly

- Add string concatenation support to + operator in typechecker
- Register ADT constructors in both type environment and interpreter
- Bind handlers as values so they can be referenced in run...with
- Fix effect checking to use subset instead of exact match
- Add built-in effects (Console, Fail, State) to run block contexts
- Suppress dead code warnings in diagnostics, modules, parser

Update all example programs with:
- Expected output documented in comments
- Proper run...with statements to execute code

Add new example programs:
- behavioral.lux: pure, idempotent, deterministic, commutative functions
- pipelines.lux: pipe operator demonstrations
- statemachine.lux: ADT-based state machines
- tailcall.lux: tail call optimization examples
- traits.lux: type classes and pattern matching

Add documentation:
- docs/IMPLEMENTATION_PLAN.md: feature roadmap and status
- docs/PERFORMANCE_AND_TRADEOFFS.md: performance analysis

Add benchmarks for performance testing.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-13 09:05:06 -05:00
parent 20bf75a5f8
commit 15a820a467
25 changed files with 1210 additions and 28 deletions

45
examples/traits.lux Normal file
View File

@@ -0,0 +1,45 @@
// Demonstrating type classes (traits) in Lux
//
// Expected output:
// RGB color: rgb(255,128,0)
// Red color: red
// Green color: green
// Define a simple Printable trait
trait Printable {
fn format(value: Int): String
}
// Implement Printable
impl Printable for Int {
fn format(value: Int): String = "Number: " + toString(value)
}
// A Color type with pattern matching
type Color =
| Red
| Green
| Blue
| RGB(Int, Int, Int)
fn colorName(c: Color): String =
match c {
Red => "red",
Green => "green",
Blue => "blue",
RGB(r, g, b) => "rgb(" + toString(r) + "," + toString(g) + "," + toString(b) + ")"
}
// Test
let myColor = RGB(255, 128, 0)
let redColor = Red
let greenColor = Green
// Print results
fn printResults(): Unit with {Console} = {
Console.print("RGB color: " + colorName(myColor))
Console.print("Red color: " + colorName(redColor))
Console.print("Green color: " + colorName(greenColor))
}
let output = run printResults() with {}