Task
Implement Set[T] as a built-in generic collection type.
Acceptance criteria
- Type syntax:
Set[Int], Set[Str], etc.
- Non-empty literal infers element type:
#{1, 2, 3} → Set[Int]
- Empty literal requires annotation:
var s: Set[Int] = #{}
- Mixed-type literals are a compile-time error
T must be hashable — compile-time error if not
- Duplicate values silently ignored on
add
- Methods:
len(), contains(value), get(value) (alias for contains), add(value), remove(value)
- Mutating methods (
add, remove) require var receiver — compile-time error on const
#{``} sigil distinguishes set literals from map literals ({}) including the empty case
Note: union, intersection, difference are defined in PDP-009 but tracked separately (deferred).
Spec
See PDP-009: Collection Types — Set[T] section.
Task
Implement
Set[T]as a built-in generic collection type.Acceptance criteria
Set[Int],Set[Str], etc.#{1, 2, 3}→Set[Int]var s: Set[Int] = #{}Tmust be hashable — compile-time error if notaddlen(),contains(value),get(value)(alias for contains),add(value),remove(value)add,remove) requirevarreceiver — compile-time error onconst#{``}sigil distinguishes set literals from map literals ({}) including the empty caseNote:
union,intersection,differenceare defined in PDP-009 but tracked separately (deferred).Spec
See PDP-009: Collection Types — Set[T] section.