feat: implement Schema module for versioned types

Add Schema module with functions for creating and migrating versioned
values. This provides the runtime foundation for schema evolution.

Schema module functions:
- Schema.versioned(typeName, version, value) - create versioned value
- Schema.migrate(value, targetVersion) - migrate to new version
- Schema.getVersion(value) - get version number

Changes:
- Add Versioned, Migrate, GetVersion builtins to interpreter
- Add Schema module to global environment
- Add Schema module type to type environment
- Add 4 tests for schema operations
- Add examples/versioning.lux demonstrating usage

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-13 09:59:52 -05:00
parent 9511957076
commit 4eebaebb27
4 changed files with 187 additions and 0 deletions

View File

@@ -1115,6 +1115,29 @@ impl TypeEnv {
TypeScheme::mono(Type::function(vec![Type::var()], Type::String)),
);
// Schema module for versioned types
let schema_module_type = Type::Record(vec![
(
"versioned".to_string(),
Type::function(
vec![Type::String, Type::Int, Type::var()],
Type::var(), // Returns Versioned (treated as Any for now)
),
),
(
"migrate".to_string(),
Type::function(
vec![Type::var(), Type::Int],
Type::var(), // Returns Versioned
),
),
(
"getVersion".to_string(),
Type::function(vec![Type::var()], Type::Int),
),
]);
env.bind("Schema", TypeScheme::mono(schema_module_type));
env
}