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について
Search
matumoto
November 04, 2023
Technology
0
200
GoのUnderlying typeについて
2023/11/04 に行われた会津大学 学祭LTの資料です
イベントページはこちら
https://zli.connpass.com/event/298894/
matumoto
November 04, 2023
Tweet
Share
More Decks by matumoto
See All by matumoto
testingを眺める
matumoto
1
150
sync/v2 プロポーザルの 背景と sync.Pool について
matumoto
0
380
Goトランザクション処理
matumoto
1
50
いまいちどスライスの 挙動を見直してみる
matumoto
0
350
Go1.22のリリース予定の機能を見る
matumoto
0
67
Typed-nilについて
matumoto
0
320
GoのType Setsという概念
matumoto
0
28
GoのRateLimit処理の実装
matumoto
0
370
Webプッシュ通知触ってみた
matumoto
0
34
Other Decks in Technology
See All in Technology
5年間のFintech × Rails実践に学ぶ - 基本に忠実な運用で築く高信頼性システム / 5 Years Fintech Rails Retrospective
ohbarye
9
3.6k
バイブコーディングと継続的デプロイメント
nwiizo
2
360
Green Tea Garbage Collector の今
zchee
PRO
2
360
about #74462 go/token#FileSet
tomtwinkle
1
260
今改めてServiceクラスについて考える 〜あるRails開発者の10年〜
joker1007
20
9.4k
pprof vs runtime/trace (FlightRecorder)
task4233
0
140
Railsアプリケーション開発者のためのブックガイド
takahashim
13
5.3k
AI時代だからこそ考える、僕らが本当につくりたいスクラムチーム / A Scrum Team we really want to create in this AI era
takaking22
1
170
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
11
77k
FastAPIの魔法をgRPC/Connect RPCへ
monotaro
PRO
1
590
非エンジニアのあなたもできる&もうやってる!コンテキストエンジニアリング
findy_eventslides
3
850
ユニットテストに対する考え方の変遷 / Everyone should watch his live coding
mdstoy
0
110
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
72
11k
Six Lessons from altMBA
skipperchong
28
4k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
890
Building a Scalable Design System with Sketch
lauravandoore
462
33k
The Invisible Side of Design
smashingmag
301
51k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
BBQ
matthewcrist
89
9.8k
Producing Creativity
orderedlist
PRO
347
40k
Scaling GitHub
holman
463
140k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.6k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.1k
Why You Should Never Use an ORM
jnunemaker
PRO
59
9.5k
Transcript
GoのUnderlying typeとは? どんなもの?なに? 彼女はいるの?調べてみました! 2023/11/04 学祭LT matumoto
• 学年:28期 • 趣味: ◦ マイクラ ◦ PokemonSleep ◦ VTuber
▪ 叶 ▪ やしきず • Twitter:@matumoto_1234 • ひとこと:マイクラに生活を破壊された matumoto 松本 響輝 自己紹介
Goの文法おさらい
Goの型エイリアス • type B = A でAを元にエイリアスを宣言できる
Goの型定義 • type B A でAを元に型を定義できる
型定義した型へのメソッド
関数とジェネリクス • 関数に型パラメータを取らせることができる
ジェネリクスの型制約 • 型パラメータに対して、型制約をかけることができる • 下のPrint関数の型引数にはintかstringしか渡せない
型制約のapproximation element • ~Tという文法で型Tを元にした型として、型制約の要素に使える
型制約のapproximation element • MyIntなどintを元にした型を渡すことができる
本題
Underlying typeとは? • 代入可能性やジェネリクスにおいての重要な概念 • すべての型はunderlying typeをちょうど一つ持つ
underlying の意味 •
例 • MyIntのunderlying typeはint
例 • intのunderlying typeはint
4つのルールによって決まる
クイズ
クイズ • MyMyStringのunderlying typeは?
正解 • 型定義はunderlying typeを共有するので、正解はstring
クイズ • struct{ x int }のunderlying typeは?
正解 • 型リテラルのunderlying typeはそれ自身
クイズ • MyIntsのunderlying typeは?
正解 • 型宣言はunderlying typeを共有するので、MyIntsのunderlying typeは[]MyIntの underlying type • 型リテラル[]MyIntのunderlying typeはそれ自身
• よって、MyIntsのunderlying typeは[]MyInt
いかがでしたか??? ありがとうございました