Safe zero-cost coercions for Haskell

Joachim Breitner, Richard A. Eisenberg, Simon Peyton Jones, Stephanie Weirich
2014 SIGPLAN notices  
Generative type abstractions -present in Haskell, OCaml, and other languages -are useful concepts to help prevent programmer errors. They serve to create new types that are distinct at compile time but share a run-time representation with some base type. We present a new mechanism that allows for zero-cost conversions between generative type abstractions and their representations, even when such types are deeply nested. We prove type safety in the presence of these conversions and have
more » ... ed our work in GHC. • We describe the design of safe coercions (Section 2), which introduces the function coerce :: Coercible a b ⇒ a → b and a new type class Coercible. This function performs a zero-cost conversion between two types a and b that have the same representation. The crucial question becomes
doi:10.1145/2692915.2628141 fatcat:afiaulg7tvar5f2kmcqccbawvu