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
Opaque Result Type in Swift with Rust
Search
Takuma Shimizu
March 27, 2019
Programming
0
110
Opaque Result Type in Swift with Rust
Takuma Shimizu
March 27, 2019
Tweet
Share
More Decks by Takuma Shimizu
See All by Takuma Shimizu
Peek in Calendar implementation of swift-foundation
hokuron
0
81
MVVM
hokuron
0
18
Summon Rust from Swift
hokuron
0
480
Generalized accessors
hokuron
0
52
Ownership of Swift as seen from iteration and Rust
hokuron
1
550
Clean Architecture 3
hokuron
0
22
Clean Architecture 2
hokuron
0
44
Create MLで犬と猫の肉球を学習
hokuron
0
68
Clean Architecture
hokuron
0
84
Other Decks in Programming
See All in Programming
Amazon SQSコンシューマー疎結合への旅 - 出張! #DevelopersIO IT技術ブログの中の人が語る勉強会 #3
quiver
0
270
Node.js v22 で変わること
yosuke_furukawa
PRO
9
3.5k
Build Apps for iOS, Android & Desktop in 100% Kotlin With Compose Multiplatform (mDevCamp 2024)
zsmb
0
340
新宿ダンジョンを可視化してみた
satoshi7190
2
260
PHP8.3の機能を振り返る / Review of PHP 8.3 features
seike460
PRO
1
110
Fragment Composition of GraphQL
quramy
7
1k
#phpcon_odawara オープン・クローズドなテストフィクスチャを求めて / open closed test fixtures
77web
3
230
Goのmultiple errorsについて (2024年4月版)
syumai
4
910
SIMD Parallel Programming with the Vector API
josepaumard
0
180
TCAとKMPを用いた新規動画配信アプリ 「ABEMA Live」の設計
tomu28
1
110
使ってみよう Azure AI Document Intelligence
kosmosebi
2
320
What We Can Learn From OSS
inouehi
0
420
Featured
See All Featured
Six Lessons from altMBA
skipperchong
21
3k
Being A Developer After 40
akosma
57
580k
How to train your dragon (web standard)
notwaldorf
73
5.2k
How to name files
jennybc
65
93k
Code Review Best Practice
trishagee
55
15k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
14
1.6k
Build The Right Thing And Hit Your Dates
maggiecrowley
24
2k
How To Stay Up To Date on Web Technology
chriscoyier
782
250k
Thoughts on Productivity
jonyablonski
58
3.8k
Making Projects Easy
brettharned
108
5.5k
Optimising Largest Contentful Paint
csswizardry
8
2.4k
Why Our Code Smells
bkeepers
PRO
331
56k
Transcript
Opaque Result Type in Swift with Rust
『Swift 5.1 に導入されそうな Opaque Result Type と は何か』 https://qiita.com/koher/items/338d2f2d0c4731e35 08f
リバースジェネリクス 通常のジェネリクス func useAnimal<A: Animal>(_ animal: A) { animal.foo() }
メソッド名に型引数を宣言 引数で型変数を利用 呼び出し側が型引数に対応する具象型を決定
リバースジェネリクス リバースジェネリクス func makeAnimal() -> <A: Animal> A { return
Cat() } メソッドシグネチャの後に型引数を宣言 返却値の型が型変数 実装側が型引数に対応する具象型を決定
Opaque Result Type some Animal を 返却値の型として利用 → リバースジェネリクス メソッド引数として利用
→ 通常のジェネリクスと同義 !!????
ジェネリクス func useAnimal<A: Animal>(_ animal: A) ↓ 型システム的な表現にすると ∀ A.
(func(A: Animal) -> ()) Opaque type func useAnimal(_ animal: some Animal) ↓ 型システム的な表現にすると (∃ A. A: Animal) -> ()
∀ A. (func(A: Animal) -> ()) ターンエーガンダムみたいななんかよく分からん記号 が、メソッドの引数から返却値まで全体にかかってい る。 (∃
A. A: Animal) -> () カタカナの「ヨ」みたいななんかよく分からん記号 は、出現場所( メソッド引数) だけにかかっている。 A. A: Animal の部分は一致している
つまり ∀ A. (func(A: Animal) -> ()) ⇔ (∃ A.
A: Animal) -> () という関係が成り立つ。 メソッド引数として利用した場合、通常のジェネリク スと同義 → 同じではないが、同形をとる
なぜプロトコル型に パフォーマンス上のロスがあるのか
Demo with Rust