Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
3
25k
Keep Calm and Type Erase On
Try!Swift 2016
Gwendolyn Weston
March 03, 2016
Tweet
Share
More Decks by Gwendolyn Weston
See All by Gwendolyn Weston
While Your App is Sleeping
gwengrid
3
650
Other Decks in Technology
See All in Technology
Snowflake導入から1年、LayerXのデータ活用の現在 / One Year into Snowflake: How LayerX Uses Data Today
civitaspo
0
2.4k
普段使ってるClaude Skillsの紹介(by Notebooklm)
zerebom
8
2.2k
ハッカソンから社内プロダクトへ AIエージェント ko☆shi 開発で学んだ4つの重要要素
leveragestech
0
180
Introduce marp-ai-slide-generator
itarutomy
0
130
Authlete で実装する MCP OAuth 認可サーバー #CIMD の実装を添えて
watahani
0
180
_第4回__AIxIoTビジネス共創ラボ紹介資料_20251203.pdf
iotcomjpadmin
0
130
Entity Framework Core におけるIN句クエリ最適化について
htkym
0
120
2025-12-27 Claude CodeでPRレビュー対応を効率化する@機械学習社会実装勉強会第54回
nakamasato
4
1k
会社紹介資料 / Sansan Company Profile
sansan33
PRO
11
390k
Knowledge Work の AI Backend
kworkdev
PRO
0
260
New Relic 1 年生の振り返りと Cloud Cost Intelligence について #NRUG
play_inc
0
240
AI駆動開発の実践とその未来
eltociear
2
490
Featured
See All Featured
Faster Mobile Websites
deanohume
310
31k
Embracing the Ebb and Flow
colly
88
4.9k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.8k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
0
1k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.7k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
190
30 Presentation Tips
portentint
PRO
1
170
AI: The stuff that nobody shows you
jnunemaker
PRO
1
24
Reflections from 52 weeks, 52 projects
jeffersonlam
355
21k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
130
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
1.8k
The SEO identity crisis: Don't let AI make you average
varn
0
39
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) } }