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:
@@ -11,12 +11,15 @@ use crate::ast::types::{Purity, RecordLayout, Signature, StaticType, Value};
|
||||
// ============================================================================
|
||||
|
||||
pub fn register(env: &Environment) {
|
||||
// (series lookback_limit template_or_type_keyword) -> Series
|
||||
// (series lookback_limit) -> Series
|
||||
// The element type is inferred by the HM type checker from subsequent push calls.
|
||||
// After type checking, the compiler elaborates (series n) into (series n schema)
|
||||
// so the runtime always receives the explicit schema argument.
|
||||
env.register_native_fn(
|
||||
"series",
|
||||
StaticType::Function(Box::new(Signature {
|
||||
params: StaticType::Tuple(vec![StaticType::Int, StaticType::Any]),
|
||||
ret: StaticType::Any,
|
||||
params: StaticType::Tuple(vec![StaticType::Int]),
|
||||
ret: StaticType::Series(Box::new(StaticType::Any)),
|
||||
})),
|
||||
Purity::Impure,
|
||||
|args: &[Value]| {
|
||||
|
||||
Reference in New Issue
Block a user