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
Keep Calm and Type Erase On
Search
Gwendolyn Weston
March 03, 2016
Technology
25k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Keep Calm and Type Erase On
Try!Swift 2016
Gwendolyn Weston
March 03, 2016
More Decks by Gwendolyn Weston
See All by Gwendolyn Weston
While Your App is Sleeping
gwengrid
3
660
Other Decks in Technology
See All in Technology
ブラウザアプリの継続的パフォーマンスモニタリング (序) / Continuous Browser Application Performance Monitoring; Act 1
moznion
0
110
enechainの内製セルフサービスプラットフォーム
hiyosi
0
110
Beyond the Hype: Practical AI for Your Oracle Database with MCP
thatjeffsmith
1
260
生成AIのテナント制御とシャドーMCP対策 | AIを"止めずに"、情報を守る
yukun
0
120
全員がプロダクトへ向き合う組織を持続成長させるために——組織づくりのフライホイールと4象限 / The Flywheel Model and Four Quadrants for Organizational Design
hiro_torii
3
830
#jawssonic2026 あの時代が悪かった ~動かなかったSageMakerと共に迎えたイベント当日~
ktkn1129
0
130
KAEN Company Deck
kaen
PRO
0
320
AI 駆動 Terraform 開発/SRE_BizReach_MIXI_2
visional_engineering_and_design
1
630
AndroidでHDRメディアを「壊さずに」扱う
chigichan24
0
400
[DroidKaigi 2026] Making UI specifications visible: Android UI development in the AI agent era supported by Compose Screenshot Testing and galleries
syarihu
0
570
From Vanilla Kubernetes to a Batteries-Included Platform: Developer Experience at 1,300+ Clusters
yosshi_
0
370
Where Is JetBrains AI Heading- — Central CLI, Air Alpha, and the Agentic Development Stack
x5gtrn
PRO
0
130
Featured
See All Featured
HDC tutorial
michielstock
2
850
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
The Limits of Empathy - UXLibs8
cassininazir
1
640
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
420
A designer walks into a library…
pauljervisheath
211
25k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
Skip the Path - Find Your Career Trail
mkilby
1
220
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
Discover your Explorer Soul
emna__ayadi
2
1.3k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
410
Transcript
Keep Calm and Type Erase On Gwendolyn Weston @purpleyay
Why would you want to erase a type? !
What does it mean to erase a type? !
What is a type? !
A type is a classification that defines: • a set
of values • and the legal operations on them
Example: Int Values: all integers in [-∞, ∞] Operations: ➕,
✖ , %
Compilers ! Types
Compilers ! (Some) Types
Two kinds of types ! Concrete types ! Abstract types
"
Concrete types ! A type with unambiguous implementation; can be
instantiated directly.
Concrete types are representations of data.
let concreteInt = 42 let concreteArray = ["much", "concrete", "wow"]
Abstract types ! A type with incomplete implementation; cannot be
instantiated directly
Abstract types are representations of behaviour.
class GenericClass<T> { ... } let object: GenericClass<T> // !
struct GenericStruct<U> { ... } let object: GenericStruct<U> // !
How to make abstract types concrete?
Type reification Making an abstract type concrete by filling in
its placeholder types
Type parameters <T>, <U>
! + <T> = " class GenericClass<T> { ... }
let StringClass: GenericClass<String> // ! struct GenericStruct<T> { ... } let IntStruct: GenericStruct<Int> // !
One exception
protocol + <T> = ! We cannot use type parameters
for generic protocols
protocol Pokemon { typealias PokemonType func attack(move:PokemonType) } class Pikachu:
Pokemon { func attack(move: Electric) { ⚡ } } class Charmander: Pokemon { func attack(move: Fire) { " } }
let pokemon: Pokemon pokemon.attack(selectedAttack)
⾠! let pokemon: Pokemon Protocol Pokemon can only be used
as a generic constraint because it has Self or associated type requirements
AnyPokemon class AnyPokemon <PokemonType>: Pokemon { required init<U:Pokemon where U.PokemonType
== PokemonType>(_ pokemon: U) { } }
let p1 = AnyPokemon(Pikachu()) let p2: AnyPokemon<Fire> p2 = AnyPokemon(Charmander())
let digimon = AnyPokemon(NotAPokemon()) //!
let pokemon = Pikachu() vs. let pokemon: AnyPokemon <Electric> pokemon
= AnyPokemon(Pikachu()) Pikachu is instantiated as type AnyPokemon <Electric>
Type erasure
Type erasure scaffolding?
let pokemon: AnyPokemon <AnyObject> pokemon = AnyPokemon(Pikachu()) //!
No covariance Swift does not allow <Electric> to substitute <AnyObject>
Downsides • Boilerplate • Lost type information • No covariance
Recap • What is a type? • 2 kinds of
types: concrete, abstract • Reification with type parameters • Type erasure
Thanks! @purpleyay
Example class AnyPokemon <PokemonType>: Pokemon { private let _attack: ((PokemonType)
-> Void) required init<U:Pokemon where U.PokemonType == PokemonType>(_ pokemon: U) { _attack = pokemon.attack } func attack(type:PokemonType) { return _attack(type) } }