-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Milestone
Description
Summary
Introduce a built-in list[T] type with Python-like literals ([]) and a minimal, type-safe method set.
Proposed Syntax
Type syntax
list[T]
Literal syntax
- Empty list:
[] - Non-empty list:
[a, b, c]
Method syntax
xs.len() -> Intxs.contains(value: T) -> Boolxs.get(index: Int) -> IndexError!Txs.add(value: T) -> Unit(mutating)xs.remove(index: Int) -> IndexError!T(mutating, remove-at-index)
Type Inference Rules
const xs = [1, 2, 3]inferslist[int]- Empty list literals require annotation:
const xs: list[int] = []var ys: list[str] = []
Type Safety Rules
- All list elements must be assignable to
T - Mixed-type literals are invalid unless explicitly typed as
list[any] - No implicit
anyinference from list literals
Mutability Rule
constforbids rebinding- Mutating methods (
add,remove) require a mutable receiver (var) - Example:
- Invalid:
const xs = [1, 2]; xs.add(3); - Valid:
var xs = [1, 2]; xs.add(3);
- Invalid:
Scope (Minimal)
- Parser support for:
list[T]in type positions- list literals:
[],[x, y] - method calls on list values (existing call/field syntax)
- Type checker support for:
- inference for non-empty list literals
- element type validation
- explicit-type requirement for empty list literals
- list method signatures and mutable-receiver checks
- Interpreter support for:
- list runtime value
- method dispatch/intrinsics for
len,contains,get,add,remove
Out of Scope
- User-defined generics
- Full list method surface area
- Slices/ranges syntax
- Stack API (
push/pop) — reserved for future stack type
Acceptance Criteria
- Valid:
const xs: list[int] = [1, 2, 3]var xs = [1, 2, 3]; xs.add(4);const n: Int = [1, 2, 3].len();
- Invalid (type errors):
const xs: list[int] = [1, "x"]const xs = [](no annotation)const xs = [1, 2]; xs.add(3);
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels