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:
@@ -596,6 +596,21 @@ impl StaticType {
|
||||
.map(|sig| sig.ret.clone()),
|
||||
StaticType::PolymorphicFn { resolve_return, .. } => resolve_return(args_ty),
|
||||
StaticType::TypeVar(_) => Some(StaticType::Any),
|
||||
// Lookback indexing: (my-series 0) → element type
|
||||
StaticType::Series(inner) => {
|
||||
let is_int = matches!(
|
||||
args_ty,
|
||||
StaticType::Int | StaticType::Any | StaticType::TypeVar(_)
|
||||
) || matches!(args_ty, StaticType::Tuple(elems)
|
||||
if elems.len() == 1
|
||||
&& matches!(&elems[0], StaticType::Int | StaticType::Any | StaticType::TypeVar(_))
|
||||
);
|
||||
if is_int {
|
||||
Some(*inner.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user