TwoFace values: a bridge between terms and types
summary
Scala 2.13 literal types plus the singleton-ops library let types and terms convert both ways: literal types, TwoFace values, compile-time checks, runtime fallback. The library uses whitebox macros to evaluate type-level math (plus, minus, comparisons, if-then-else) and provides TwoFace value classes so a fixed-size vector’s size can be computed and checked at compile time (falling back to a runtime exception if unknown), with examples that reject size 0 with the message "size must be positive". It notes symbol deprecation and partial Scala 3 support.
AI-written summary · about
chapters (16)
- 0:00Introduction
- 1:10Scala 2.13 and singleton types
- 3:22Literal types and upper bounds
- 8:56Singleton type limitations
- 10:48Singleton ops library
- 12:11How singleton ops works
- 13:57Compile-time calculations with ops
- 17:15Compile-time constraints with ops
- 19:47Introducing TwoFace values
- 20:32Compile-time inlining with TwoFace
- 22:45TwoFace shells for compile-time
- 25:20Checked values with TwoFace
- 26:51Size and bounds checks with TwoFace
- 29:32Pitfalls and improvements
- 31:44Conclusion and future
- 32:05Acknowledgments and Q&A
related talks
35mLiteral types what they are good for
49mType level Programming in Scala
45mTypelevel Programming 101: The Subspace of Scala
38mThinking in Scala 3 Types
32mUnderstanding the Type System of Scala 3
32mSingle Serving Values with Linear Types in Scala
01h 01mTypesafe Scala, Typelevel Scala – What’s Going On, Anyway?
32mAdvanced Features of Scala 3
