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

55
examples/pipelines.lux Normal file
View File

@@ -0,0 +1,55 @@
// Demonstrating the pipe operator and functional data processing
//
// Expected output:
// 5 |> double |> addTen |> square = 400
// Pipeline result2 = 42
// process(1) = 144
// process(2) = 196
// process(3) = 256
// clamped = 0
// composed = 121
// Basic transformations
fn double(x: Int): Int = x * 2
fn addTen(x: Int): Int = x + 10
fn square(x: Int): Int = x * x
fn negate(x: Int): Int = -x
// Using the pipe operator for data transformation
let result1 = 5 |> double |> addTen |> square
// Chaining multiple operations
let result2 = 3 |> double |> addTen |> double |> addTen
// More complex pipelines
fn process(n: Int): Int =
n |> double |> addTen |> square
// Multiple values through same pipeline
let a = process(1)
let b = process(2)
let c = process(3)
// Conditional in pipeline
fn clampPositive(x: Int): Int =
if x < 0 then 0 else x
let clamped = -5 |> double |> clampPositive
// Function composition using pipe
fn increment(x: Int): Int = x + 1
let composed = 5 |> double |> increment |> square
// Print results
fn printResults(): Unit with {Console} = {
Console.print("5 |> double |> addTen |> square = " + toString(result1))
Console.print("Pipeline result2 = " + toString(result2))
Console.print("process(1) = " + toString(a))
Console.print("process(2) = " + toString(b))
Console.print("process(3) = " + toString(c))
Console.print("clamped = " + toString(clamped))
Console.print("composed = " + toString(composed))
}
let output = run printResults() with {}