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
160
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
430
Peek in Calendar implementation of swift-foundation
hokuron
0
190
MVVM
hokuron
0
51
Summon Rust from Swift
hokuron
0
680
Generalized accessors
hokuron
0
81
Ownership of Swift as seen from iteration and Rust
hokuron
1
690
Clean Architecture 3
hokuron
0
54
Clean Architecture 2
hokuron
0
69
Create MLで犬と猫の肉球を学習
hokuron
0
100
Other Decks in Programming
See All in Programming
2分台で1500examples完走!爆速CIを支える環境構築術 - Kaigi on Rails 2025
falcon8823
3
3.6k
GraphQL×Railsアプリのデータベース負荷分散 - 月間3,000万人利用サービスを無停止で
koxya
1
1.3k
(Extension DC 2025) Actor境界を越える技術
teamhimeh
1
250
Introducing ReActionView: A new ActionView-Compatible ERB Engine @ Kaigi on Rails 2025, Tokyo, Japan
marcoroth
3
1k
NixOS + Kubernetesで構築する自宅サーバーのすべて
ichi_h3
0
720
After go func(): Goroutines Through a Beginner’s Eye
97vaibhav
0
380
dynamic!
moro
10
7.7k
明日から始めるリファクタリング
ryounasso
0
140
Devvox Belgium - Agentic AI Patterns
kdubois
1
120
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
290
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
0
240
Pull-Requestの内容を1クリックで動作確認可能にするワークフロー
natmark
2
500
Featured
See All Featured
KATA
mclloyd
32
15k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
6.1k
Building Adaptive Systems
keathley
43
2.8k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
19
1.2k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.2k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.6k
Music & Morning Musume
bryan
46
6.8k
Building Applications with DynamoDB
mza
96
6.7k
Why You Should Never Use an ORM
jnunemaker
PRO
59
9.6k
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