Upgrade to Pro — share decks privately, control downloads, hide ads and more …

空の型セットを検出したい

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

 空の型セットを検出したい

Avatar for nobishii

nobishii

May 18, 2021
Tweet

More Decks by nobishii

Other Decks in Programming

Transcript

  1. 目次 - 背景: 型パラメータと型制約と型セット - 型セットの具体例 - 問題: 空の型セット -

    Underlying type - サンプルコード: Underlying typeが自分自身かどうかを判定する - 参考資料
  2. 背景 - 型パラメータ(ジェネリクス) Proposal: accepted - 型制約をinterfaceとして記述する - 型セットProposal: acceptedではないけどacceptされそうな状況

    - 型制約の記述方法を改善するもの - 全ての型は、型セットを持つ - 「型Tがinterface Iを実装する」は「型TがIの型セットに属する」と同じ意味になる
  3. underlying typeとは - ~Tは、「underlying typeがTである ような全ての型」の集合 - ~int は{int ,

    MyInt, MyMyInt, …} - ~MyInt は {} (空集合) - underlying typeがMyIntになるよう な型は存在しないから - intの特徴: underlying typeが自分 自身
  4. 判定方法 - ~SomeTypeをParseする(※今日は行いません) - SomeTypeのunderlying typeがSomeTypeに等しいかどうか調べる - 使う関数: - (*types.Package).Scope()

    *types.Scope - パッケージレベルで宣言されたモノを取得 - (*types.Scope).Lookup(name string) types.Object - Scopeから名前で検索 - (types.Type).Underlying() types.Type - ある型のunderlying typeを返す
  5. 参考資料 - Go公式資料 - Type Parameters Proposal 型パラメータ(ジェネリクス)に関するProposal(accepted) - https://github.com/golang/go/issues/45346

    型セットに関するProposal - その他資料 - Go の "Type Sets" proposal を読む - underlying types by DQNEOさん - 発表アーカイブ動画 - 勇者さま一行のイラストは いらすとや様からお借りしました