Add IndexElementFn for series type probing
Introduce `IndexElementFn` as a type alias for a function that maps a `StaticType` to an optional `StaticType` representing its element type. This allows the `TypeChecker` to determine the element type of indexable types like `Series` without needing to be aware of their specific implementations. The `series_element_type` function is created and registered with the `TypeChecker` to handle `Series` types. This design centralizes type-specific logic for indexable types, making the `TypeChecker` more generic and extensible for future indexable types such as `Stream`.
This commit is contained in:
@@ -15,6 +15,21 @@ use crate::ast::types::{NativeFunction, NodeIdentity, Purity, Signature, SourceL
|
||||
// 4. Type-Inference Hooks (registered via RTL bootstrap, no name coupling)
|
||||
// ============================================================================
|
||||
|
||||
/// Index-element hook for the `Series` type.
|
||||
///
|
||||
/// Returns the element type of a `Series(inner)`, or `None` for all other types.
|
||||
/// Registered with `TypeChecker` so that the core type-checker remains agnostic
|
||||
/// about which concrete types support integer-index access.
|
||||
///
|
||||
/// When `Stream` (or future indexable types) is added, extend this function
|
||||
/// with additional match arms rather than touching the type-checker.
|
||||
pub(crate) fn series_element_type(ty: &StaticType) -> Option<StaticType> {
|
||||
match ty {
|
||||
StaticType::Series(inner) => Some(*inner.clone()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Post-call hook for `(series n)`.
|
||||
/// Replaces the `Series(Any)` return type with a fresh TypeVar so that
|
||||
/// subsequent `push` calls can unify the element type (HM inference).
|
||||
|
||||
Reference in New Issue
Block a user