Please log in to watch this conference skillscast.
Newtypes are the key to data abstraction in Haskell, and come with an crucial performance guarantee: it doesn’t cost anything to use a newtype.
Embarrassingly, this guarantee is weak: it fails as soon as you embed a newtype’d value in a data structure. At the same time, the hugely-popular language feature “generalised newtype deriving” turns out to rely internally on a strong version of the guarantee. And, in the presence of type-level functions, the strong version of the guarantee turns out to be unsound, leading to a notorious type-soundness bug in GHC that has persisted for several years.
As is often the case in Haskell, finding a solid, principled solution to the problem turned out to be far more interesting than we expected, requiring us to distinguish two flavours of type equality (representational and nominal), with a “role system” to allow type-safe abstraction. I think the result is pretty cool. In this talk I’ll explain what all the fuss is about.
YOU MAY ALSO LIKE:
Safe, Zero-Cost Coercions in Haskell
Simon Peyton Jones, MA, MBCS, CEng, graduated from Trinity College Cambridge in 1980. Simon was a key contributor to the design of the now-standard functional language Haskell, and is the lead designer of the widely-used Glasgow Haskell Compiler (GHC). He has written two textbooks about the implementation of functional languages.