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
150
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
380
Peek in Calendar implementation of swift-foundation
hokuron
0
160
MVVM
hokuron
0
44
Summon Rust from Swift
hokuron
0
640
Generalized accessors
hokuron
0
72
Ownership of Swift as seen from iteration and Rust
hokuron
1
640
Clean Architecture 3
hokuron
0
38
Clean Architecture 2
hokuron
0
58
Create MLで犬と猫の肉球を学習
hokuron
0
93
Other Decks in Programming
See All in Programming
技術を改善し続ける
gumioji
0
190
はじめてのIssueOps - GitHub Actionsで実現するコメント駆動オペレーション
tmknom
5
1.7k
Swift Testingのモチベを上げたい
stoticdev
2
220
iOSでQRコード生成奮闘記
ktcryomm
2
150
Domain-Driven Design (Tutorial)
hschwentner
13
22k
1年目の私に伝えたい!テストコードを怖がらなくなるためのヒント/Tips for not being afraid of test code
push_gawa
1
670
Datadog Workflow Automation で圧倒的価値提供
showwin
1
340
Visual StudioのGitHub Copilotでいろいろやってみる
tomokusaba
1
240
From the Wild into the Clouds - Laravel Meetup Talk
neverything
0
190
Jakarta EE meets AI
ivargrimstad
0
890
Generating OpenAPI schema from serializers throughout the Rails stack - Kyobashi.rb #5
envek
1
450
高セキュリティ・高耐障害性・サブシステム化。そして2億円
tasukulab280
2
410
Featured
See All Featured
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.3k
How to Ace a Technical Interview
jacobian
276
23k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Large-scale JavaScript Application Architecture
addyosmani
511
110k
Fontdeck: Realign not Redesign
paulrobertlloyd
83
5.4k
Gamification - CAS2011
davidbonilla
80
5.2k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7.1k
Documentation Writing (for coders)
carmenintech
69
4.6k
How to Think Like a Performance Engineer
csswizardry
22
1.4k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.5k
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