Refactor: Simplify series creation and infer element type

The `series` constructor now only accepts the `lookback` limit. The
element type is inferred by the type checker and implicitly added as a
schema argument during compilation. This simplifies the API and
centralizes type inference.

This change also includes:
- Updates to example scripts (`HMA.myc`, `sma.myc`, `soa_series.myc`) to
  reflect the new `series` signature.
- Modifications to the `TypeChecker` to handle the inferred schema
  injection.
- An addition of a regression test for type inference through nested
  closures with `series`.
- Removal of `#[allow(dead_code)]` from several `TypeChecker` methods as
  they are now used.
- Update to `rtl/prelude.myc` macro `cache`.
- Update to `rtl/series/mod.rs` to reflect new signature.
- Update to `ast/types.rs` to allow `series` to be indexed with an
  integer to retrieve its element type.
This commit is contained in:
2026-03-28 13:47:15 +01:00
parent e595e747d4
commit d2cba2d55d
10 changed files with 284 additions and 19 deletions
+30
View File
@@ -10,6 +10,36 @@ fn test_series_api_with_limit() {
assert!(result.is_ok(), "Series creation with limit should work: {:?}", result.err());
}
/// Regression test for HM type inference through nested closures.
///
/// `series` is created in an outer closure, `push` happens in an inner closure.
/// The pushed value type must propagate back through the TypeVar chain so that
/// the compiler can inject the `:float` schema — no explicit schema given.
#[test]
fn test_series_infer_type_from_nested_closure() {
let env = Environment::new();
let source = r#"
(do
(def make-acc
(fn [n]
(do
(def s (series n))
(def total 0.0)
(fn [x]
(do
(assign total (+ total x))
(push s x)
(s 0))))))
(def acc (make-acc 5))
(acc 1.5))
"#;
let result = env.run_script(source);
match result {
Ok(Value::Float(v)) if (v - 1.5).abs() < 1e-9 => {}
other => panic!("Expected Float(1.5), got {:?}", other),
}
}
#[test]
fn test_record_structural_equality_order() {
let env = Environment::new();