Task
Define and implement the hashability convention for Pipe types, required for Map[K, V] keys and Set[T] elements.
Convention
A type T is hashable if:
- It is a built-in primitive (
Int, Str, Bool, Float) — built-in hash() provided, or
- It defines a
hash() -> Int method
This mirrors the toString() convention: built-in implementations exist for primitives; structs opt in by defining hash().
Equality semantics
- Primitives: value equality
- Regular structs: identity (address) equality by default
- Case structs, or structs defining
eql() -> Bool: value equality
A regular struct without hash() is still hashable via address (identity-based sets and maps).
A struct with hash() should also define eql(); the compiler may warn if only one is defined.
Acceptance criteria
- Built-in
hash() for primitives (Int, Str, Bool, Float)
- Structs can opt in via
hash() -> Int method
- Using a non-hashable type as
K in Map[K, V] or T in Set[T] is a compile-time type error
- Compiler warns when a struct defines
hash() but not eql(), or vice versa (TBD — see open question in PDP-009)
Spec
See PDP-009: Collection Types — Hashability section.
Task
Define and implement the hashability convention for Pipe types, required for
Map[K, V]keys andSet[T]elements.Convention
A type
Tis hashable if:Int,Str,Bool,Float) — built-inhash()provided, orhash() -> IntmethodThis mirrors the
toString()convention: built-in implementations exist for primitives; structs opt in by defininghash().Equality semantics
eql() -> Bool: value equalityA regular struct without
hash()is still hashable via address (identity-based sets and maps).A struct with
hash()should also defineeql(); the compiler may warn if only one is defined.Acceptance criteria
hash()for primitives (Int,Str,Bool,Float)hash() -> IntmethodKinMap[K, V]orTinSet[T]is a compile-time type errorhash()but noteql(), or vice versa (TBD — see open question in PDP-009)Spec
See PDP-009: Collection Types — Hashability section.