Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
入門Go言語仕様 Underlying Type / Go Language Underlyi...
Search
DQNEO
February 18, 2021
Programming
9
4.8k
入門Go言語仕様 Underlying Type / Go Language Underlying Type
Go言語の “Underlying Type” の仕組みをわかりやすく解説します。
Go言語の設計原則や歴史にもせまります。
#gospecreading
DQNEO
February 18, 2021
Tweet
Share
More Decks by DQNEO
See All by DQNEO
英和辞書付きGo言語仕様書 / Word Wise Go Spec
dqneo
1
480
Go言語低レイヤー入門 Hello world が 画面に表示されるまで / Introduction to low level programming in Go
dqneo
6
1.5k
入門Go言語仕様 / Go Specification Untyped Constants
dqneo
1
1.2k
How to write a self hosted Go compiler from scratch (Gophercon 2020)
dqneo
3
1.5k
もっと気軽にOSSに Pull Requestを出そう!/ Let's make a PR to OSS more easily
dqneo
6
8.2k
Goコンパイラをゼロから作ってセルフホスト達成するまで / How I wrote a self hosted Go compiler from scratch
dqneo
15
14k
コンパイラをつくってみよう / How to make a compiler
dqneo
9
11k
コンパイラ作りの魅力を語る / Making compilers is fun
dqneo
10
8.4k
Goのmapとheapを自作してみた / How to create your own map and heap in Go
dqneo
0
3.1k
Other Decks in Programming
See All in Programming
時計仕掛けのCompose
mkeeda
1
300
動作確認やテストで漏れがちな観点3選
starfish719
6
1k
法律の脱レガシーに学ぶフロントエンド刷新
oguemon
5
740
技術を根付かせる / How to make technology take root
kubode
1
250
2024年のWebフロントエンドのふりかえりと2025年
sakito
2
250
pylint custom ruleで始めるレビュー自動化
shogoujiie
0
120
定理証明プラットフォーム lapisla.net
abap34
1
1.8k
Grafana Loki によるサーバログのコスト削減
mot_techtalk
1
130
『テスト書いた方が開発が早いじゃん』を解き明かす #phpcon_nagoya
o0h
PRO
2
210
Honoをフロントエンドで使う 3つのやり方
yusukebe
7
3.3k
XStateを用いた堅牢なReact Components設計~複雑なClient Stateをシンプルに~ @React Tokyo ミートアップ #2
kfurusho
1
900
お前もAI鬼にならないか?👹Bolt & Cursor & Supabase & Vercelで人間をやめるぞ、ジョジョー!👺
taishiyade
6
4k
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
174
51k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
114
50k
How STYLIGHT went responsive
nonsquared
98
5.4k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
What's in a price? How to price your products and services
michaelherold
244
12k
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
Rails Girls Zürich Keynote
gr2m
94
13k
The Invisible Side of Design
smashingmag
299
50k
Transcript
入門Go言語仕様輪読会 “Underlying Type” @DQNEO 2021-02-18 20:10
自己紹介 • @DQNEO (ドキュネオ) • Goコンパイラ babygo の作者です ◦ https://github.com/DQNEO/babygo
• 公式Goコンパイラ コントリビュート歴有り • Go言語仕様書 コントリビュート歴有り(←New)
全ての型には “Underlying Type” がある
underlyingの意味 lying or situated under something --- Oxford’s Languages
underlying type = 背後霊 私 霊
“Underlying Type”がなぜ重要なのか • Assignability (代入可能性) の条件に使われている • Generics で重要な役割をになう ◦
設計ドラフトで “underlying type” が11回登場 https://go.googlesource.com/proposal/+/refs/heads/ master/design/go2draft-type-parameters.md
例 type MyInt int MyInt の underlying type は int
イメージ 背後霊 MyInt int type MyInt int
全ての型には “Underlying Type” がある = 全ての型には 背後霊型がある
MyInt int では int の underlying type は? type MyInt
int ?
int int int の underlying type は int
ルール1: predeclared な boolean, numeric, string の underlyng type は
自分自身 ルール2: 型リテラルの underlyng type は自分自身 ルール3: 型定義すると、左側と右側で underlyng type を共有する 3つのルール
predeclaredな boolean,string,numeric のunderlying typeは自分自身 ルール1 • bool • string •
int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 uintptr complex64 complex128 float32 float64
複合的な型 type User struct { id int name string }
User struct { id int name string } 背後霊
struct{...}の underlying type は? struct { id int name string
}
struct { id int name string } struct { id
int name string } struct{...}の underlying typeは自分自身
型リテラルの underlying typeは 自分自身 ルール2 例: *int struct{...} []string map[int]bool
interface{...} ※前半発表のNobishiiさん の資料もご参照ください。
type MyInt int MyInt int 派生型から派生させると? type MyMyInt MyInt MyMyInt
誰?
int type MyInt int MyInt int 派生型から派生させると? type MyMyInt MyInt
MyMyInt えっ?
型定義をすると、 左側と右側が underlying typeを共有する ルール3 type B A 左 右
※前半発表のNobishiiさんの資料も ご参照ください
背後霊を共有する type B A B A Aの背後霊
type MyInt int MyInt int int 背後霊を共有する
type MyMyInt MyInt MyMyInt MyInt int 背後霊を共有する
type User struct{ id… } User struct{id...} struct{id...} 背後霊を共有する
type AdminUser User AdminUser User struct{id...} 背後霊を共有する
type MyInt int type MyMyInt MyInt type MyMyMyInt MyMyInt MyInt
int int フラットな組織 MyMyInt MyMyMyInt
func (x MyInt) method() { } MyInt int int Method
の継承 MyMyInt MyMyMyInt method なし method なし method なし method あり method なし
Method の継承 A defined type may have methods associated with
it. It does not inherit any methods bound to the given type, but the method set of an interface type or of elements of a composite type remains unchanged: • interface型 : 継承される • 構造体型の要素のメソッド: 継承される • それ以外の型: 継承されない
型のヒエラルキー (段階的階層)がない
Go言語誕生の背景 https://talks.golang.org/2009/go_talk-20091030.pdf
https://talks.golang.org/2009/go_talk-20091030.pdf Go言語の設計原則
ルール1: predeclared boolean, numeric, string の underlyng type は自分自身 ルール2:
型リテラルの underlyng type は自分自身 ルール3: 型定義すると、左側と右側で underlyng type を共有する まとめ
None
クイズ1 type ( B1 string B2 B1 ) string, B1,
B2 の それぞれの underlying type は? → 答えは言語仕様書に
クイズ2 type ( B1 string B2 B1 B3 []B1 B4
B3 ) [ ]B1, B3, B4 のそれぞれの underlying type は? → 答えは言語仕様書に
ご清聴 ありがとうございました