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
140
Opaque Result Type in Swift with Rust
Takuma Shimizu
March 27, 2019
Tweet
Share
More Decks by Takuma Shimizu
See All by Takuma Shimizu
Swift Attributes
hokuron
0
370
Peek in Calendar implementation of swift-foundation
hokuron
0
150
MVVM
hokuron
0
43
Summon Rust from Swift
hokuron
0
630
Generalized accessors
hokuron
0
67
Ownership of Swift as seen from iteration and Rust
hokuron
1
630
Clean Architecture 3
hokuron
0
35
Clean Architecture 2
hokuron
0
54
Create MLで犬と猫の肉球を学習
hokuron
0
89
Other Decks in Programming
See All in Programming
Vue.jsでiOSアプリを作る方法
hal_spidernight
0
120
定理証明プラットフォーム lapisla.net
abap34
1
670
“あなた” の開発を支援する AI エージェント Bedrock Engineer / introducing-bedrock-engineer
gawa
10
1.4k
混沌とした例外処理とエラー監視に秩序をもたらす
morihirok
18
3.3k
Azure AI Foundryのご紹介
qt_luigi
1
260
Simple組み合わせ村から大都会Railsにやってきた俺は / Coming to Rails from the Simple
moznion
3
3.8k
AWS re:Invent 2024個人的まとめ
satoshi256kbyte
0
150
AHC041解説
terryu16
0
550
Immutable ActiveRecord
megane42
0
120
個人アプリを2年ぶりにアプデしたから褒めて / I just updated my personal app, praise me!
lovee
0
310
DevinとCursorから学ぶAIエージェントメモリーの設計とMoatの考え方
itarutomy
1
500
さいきょうのレイヤードアーキテクチャについて考えてみた
yahiru
1
540
Featured
See All Featured
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
Site-Speed That Sticks
csswizardry
3
310
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
The Cult of Friendly URLs
andyhume
78
6.2k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
6
220
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
27
1.9k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
Fireside Chat
paigeccino
34
3.2k
Agile that works and the tools we love
rasmusluckow
328
21k
The Language of Interfaces
destraynor
156
24k
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