docs: add demos and update documentation for new features

Documentation:
- Update IMPLEMENTATION_PLAN.md with current status (222 tests)
- Update feature comparison table (Schema Evolution, Behavioral Types: )
- Add HttpServer to built-in effects list
- Update OVERVIEW.md with working behavioral types examples

Demo Programs:
- examples/schema_evolution.lux - Version annotations, constraints, runtime ops
- examples/behavioral_types.lux - pure, deterministic, commutative, idempotent, total

Sample Project:
- projects/rest-api/ - Full REST API demo with:
  - Task CRUD endpoints
  - Pattern matching router
  - JSON serialization
  - Effect-tracked request handling

Tests:
- Add behavioral type tests (pure, deterministic, commutative, idempotent, total)
- 227 tests passing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-13 22:14:55 -05:00
parent 086552b7a4
commit 705bd57e81
7 changed files with 699 additions and 43 deletions

View File

@@ -2254,6 +2254,86 @@ c")"#;
assert!(result.is_ok(), "HttpServer type checking failed: {:?}", result);
}
// Behavioral types tests
#[test]
fn test_behavioral_pure_function() {
use crate::parser::Parser;
use crate::typechecker::TypeChecker;
let source = r#"
fn add(a: Int, b: Int): Int is pure = a + b
fn square(x: Int): Int is pure = x * x
let result = add(square(3), square(4))
"#;
let program = Parser::parse_source(source).expect("parse failed");
let mut checker = TypeChecker::new();
assert!(checker.check_program(&program).is_ok());
}
#[test]
fn test_behavioral_deterministic() {
use crate::parser::Parser;
use crate::typechecker::TypeChecker;
let source = r#"
fn factorial(n: Int): Int is deterministic =
if n <= 1 then 1 else n * factorial(n - 1)
let result = factorial(5)
"#;
let program = Parser::parse_source(source).expect("parse failed");
let mut checker = TypeChecker::new();
assert!(checker.check_program(&program).is_ok());
}
#[test]
fn test_behavioral_commutative() {
use crate::parser::Parser;
use crate::typechecker::TypeChecker;
// Commutative verification works with arithmetic operators
let source = r#"
fn add(a: Int, b: Int): Int is commutative = a + b
fn mul(a: Int, b: Int): Int is commutative = a * b
let result = add(10, 20)
"#;
let program = Parser::parse_source(source).expect("parse failed");
let mut checker = TypeChecker::new();
assert!(checker.check_program(&program).is_ok());
}
#[test]
fn test_behavioral_idempotent() {
use crate::parser::Parser;
use crate::typechecker::TypeChecker;
// Idempotent verification works with abs pattern
let source = r#"
fn absolute(x: Int): Int is idempotent =
if x < 0 then 0 - x else x
let result = absolute(-42)
"#;
let program = Parser::parse_source(source).expect("parse failed");
let mut checker = TypeChecker::new();
assert!(checker.check_program(&program).is_ok());
}
#[test]
fn test_behavioral_total() {
use crate::parser::Parser;
use crate::typechecker::TypeChecker;
let source = r#"
fn sumTo(n: Int): Int is total =
if n <= 0 then 0 else n + sumTo(n - 1)
fn power(base: Int, exp: Int): Int is total =
if exp <= 0 then 1 else base * power(base, exp - 1)
let result = sumTo(10)
"#;
let program = Parser::parse_source(source).expect("parse failed");
let mut checker = TypeChecker::new();
assert!(checker.check_program(&program).is_ok());
}
// Math module tests
#[test]
fn test_math_abs() {