Skip to content

言語: trait / protocol(多態のための型クラス) #104

Description

@ryuichi1208

目的

"ある型が満たすべきメソッド集合" を宣言する仕組みを導入し、dict[K,V] の Hashable や class (#10) の多態の根拠を与える。

背景

提案 (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 で多態を実証

関連

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:lang言語仕様・構文・型システムenhancementNew feature or requestpriority:medium実用化のために重要

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions