Skip to content
0:00 / 0:00

#opaquetypes#sip-35#typelevel

Opaque types: understanding SIP-35 – Erik Osheim

Typelevel

2.6K subscribers • 8 videos on Hallway

YouTube
  • Recommended by 1 person: 1 in engineering communities.
  • Presented by Erik Osheim, co-founder of Typelevel

Intermediate. Assumes working knowledge.

2.2K views8 years ago1 recommendation

Programming languagesScalaLanguage design and type systems

Erik Osheim explains the motivation, design, and implementation of opaque types in Scala, comparing them to value classes and type aliases.

Proposed in SIP-35, opaque types introduce a way to define types which only exist at compile-time. Despite some superficial similarities to value classes, opaque types are significantly more flexible and introduce a number of exciting new possibilities in the Scala design space. Opaque types are motivated by a number of different concerns: - desire for a non-class type that exists only at compile-time - efficiency concerns with value classes - limitations of existing type aliases - need to better support phantom types, type tags, etc. This talk will introduce opaque types, compare them to type aliases and value classes (their two nearest cousins) and then walk through some examples of using opaque types. The focus will be on advantages of using opaque types versus other encodings, including looking at how various types are represented by the JVM at runtime. The talk does not assume in-depth knowledge of the Scala compiler and will motivate the code using plausible real world examples. Attendees will come away from this talk with a better understanding of what SIP-35 means, why it was proposed, and how it could change how we write Scala code for the better. * Material * Slides: plastic-idolatry.com/erik/nescala2018.pdf * Event * Typelevel Summit Boston, March 2018: typelevel.org/event/2018-03-summit-boston/ * About Speaker * Erik Osheim is one of the founders of Typelevel, and maintains several Scala libraries including Cats, Spire, and others. He hacks Scala for a living at Stripe, and is committed to having his cake and eating it too when it comes to functional programming. Besides programming he spends time playing music, drinking tea, and cycling around Providence, Rhode Island. * Licensing * This recording is licensed under CC-BY 4.0 (creativecommons.org/licenses/by/4.0/).

Why it's here

1 person recommends this

What people say. Recommended as a clear explanation of how opaque types work and their performance benefits over value classes.

u/joshlemerin r/scala • Recommends

Opaque types: understanding SIP-35 – Erik Osheim (x-post from /r/ScalaConferenceVideos)

u/blank101010in r/scala • Mentions

On “Opaque types replace value classes?”

…^^^^^^^^^^^^^^ // This is the second way to unlift the logarithm type def toDouble: Double = math.exp(`this`) def +(that: Logarithm): Logarithm = Logarithm(math.exp(`this`) + math.exp(that)) def *(that: Logarithm): Logarithm = Logarithm(`this` + that) } } } \1\ [video \2\ https://docs.scala-lang.org/sips/opaque-types.html…