Polymorphic Function Types in Scala 3
summary
Scala 3 adds first-class polymorphic function types, represented as a refinement that injects an apply method so the type system treats them like values (represented as refinement adding an apply method). The compiler erases type parameters and emits a monomorphic JVM shape, inserting casts as needed (erases to monomorphic function with same term arity). Real uses include Tuple.map, generic typeclass derivation, sized lists and contextual callbacks; work includes SIP-49 and a prototype for polymorphic eta-expansion and type-parameter closure inference. Overall, feature compiles and runs, but natural subtyping for poly‑function types is still pending.
AI-written summary · about
chapters (11)
- 0:00Polymorphic function types intro
- 1:16Methods vs functions in Scala
- 5:16Why polymorphic types exist
- 10:40How polymorphic functions work
- 16:47Use cases for polymorphic functions
- 21:06Generic programming with polymorphism
- 25:26Type safety with contextual polymorphism
- 29:48Improving polymorphic function usability
- 33:28Type parameter closure inference
- 36:40Natural subtyping for polymorphism
- 39:15Resources and closing
related talks
42mPolymorphic Function Types in Scala 3
32mUnderstanding the Type System of Scala 3
38mThinking in Scala 3 Types
49mType level Programming in Scala
45mHow to be polymorphic in Scala
43mAdding kind-polymorphism to the Scala programming language
51mAdding Kind-polymorphism To The Scala Programming Language
41mPolymorphism in Scala
