Newtype wrappers

Krzysztof Gogolewski krz.gogolewski at
Tue Jan 15 15:19:51 CET 2013

The idea can be extended to other situations where unsafeCoerce is
justified: empty types and phantom types. Given declarations

data Void
data Void'
data Const a b = Const a

we can create O(1) wrappers:

f :: F Void -> F Void'                   -- empty datatypes are exchangeable
g :: F (Const a Int) -> F (Const a Bool) -- phantom parameter is insignificant

assuming they do not mess with invariants of F.

More information about the Glasgow-haskell-users mailing list