## 目的 \"ある型が満たすべきメソッド集合\" を宣言する仕組みを導入し、`dict[K,V]` の Hashable や `class` (#10) の多態の根拠を与える。 ## 背景 - #8 dict[K,V] の受け入れ条件に \"hashable プロトコル\" が出てくるが、その宣言構文が言語に無い - #10 class が来たときに「継承 (subclass)」と「インターフェース (protocol)」のどちらを採るかが決まっていない - Rust trait / Go interface / Python Protocol のいずれかの形が必要 ## 提案 (drafting) Rust trait 風 + Go の構造的派生: ``` trait Hashable: def hash(self) -> u64 def equals(self, other: Self) -> bool impl Hashable for str: def hash(self) -> u64: return str_hash(self) def equals(self, other: str) -> bool: return str_eq(self, other) ``` ## 検討事項 - 構造的 (Go) か nominal (Rust impl) か - デフォルト実装の有無 - 動的ディスパッチ (`dyn Trait`) の必要性 - ジェネリクス境界 `T: Hashable` との結合 ## 受け入れ条件 - [ ] trait 宣言と impl - [ ] dict が \"K: Hashable\" 制約を受ける形に書き換え可能 - [ ] examples / tests で多態を実証 ## 関連 - 前提: ジェネリクス issue (上) - 連携: #8 (dict), #10 (class)
目的
"ある型が満たすべきメソッド集合" を宣言する仕組みを導入し、
dict[K,V]の Hashable やclass(#10) の多態の根拠を与える。背景
提案 (drafting)
Rust trait 風 + Go の構造的派生:
検討事項
dyn Trait) の必要性T: Hashableとの結合受け入れ条件
関連