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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Takuma Shimizu
March 27, 2019
Programming
180
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Opaque Result Type in Swift with Rust
Takuma Shimizu
March 27, 2019
More Decks by Takuma Shimizu
See All by Takuma Shimizu
RailsのValidatesをSwift Macrosで再現してみた
hokuron
0
180
Swift Attributes
hokuron
0
470
Peek in Calendar implementation of swift-foundation
hokuron
0
250
MVVM
hokuron
0
78
Summon Rust from Swift
hokuron
0
710
Generalized accessors
hokuron
0
89
Ownership of Swift as seen from iteration and Rust
hokuron
1
730
Clean Architecture 3
hokuron
0
71
Clean Architecture 2
hokuron
0
88
Other Decks in Programming
See All in Programming
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
380
LLM Plugin for Node-REDの利用方法と開発について
404background
0
170
New "Type" system on PicoRuby
pocke
1
780
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
120
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
520
A2UI という光を覗いてみる
satohjohn
1
120
Swiftのレキシカルスコープ管理
kntkymt
0
220
AutonomyとControlのあいだ:Graflowで記述するAIエージェント協調
myui
0
110
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
180
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
140
Webフレームワークの ベンチマークについて
yusukebe
0
150
運用エージェントは "作る" から "育てる" へ - 記憶と自己進化の3層設計パターン / self-evolving-agents-three-layer-agent-design
gawa
12
3.6k
Featured
See All Featured
Speed Design
sergeychernyshev
33
1.8k
Tell your own story through comics
letsgokoyo
1
950
Building the Perfect Custom Keyboard
takai
2
790
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
For a Future-Friendly Web
brad_frost
183
10k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
Balancing Empowerment & Direction
lara
6
1.2k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
610
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
270
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
How to make the Groovebox
asonas
2
2.2k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
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