Newtype wrappers

This page proposes newtype wrappers, a new feature for Haskell
indended to make newtypes more flexible and useful. It tackles head-on
the problem underlying #7542 and #2110.

The problem

Suppose we have

newtype Age = MkAge Int

Then if n :: Int, we can convert n to an Age thus: MkAge n :: Age.
Moreover, this conversion is a type conversion only, and involves no runtime
instructions whatsoever. This cost model -- that newtypes are free -- is important
to Haskell programmers, and encourages them to use newtypes freely to express
type distinctions without introducing runtime overhead.

Alas, the newtype cost model breaks down when we involve other data structures.
Suppose we have these declarations

Can we convert these into the corresponding forms where the Int is replaced by Age?
Alas, not easily, and certainly not without overhead.

For x1 we can write map MkAge x1 :: [Age]. But this does not follow the newtype cost model: there will be runtime overhead from executing the map at runtime, and sharing will be lost too. Could GHC optimise the map somehow? This is hard; apart from anything else, how would GHC know that map was special? And it it gets worse.

For x2 we'd have to eta-expand: (\y -> MkAge (x2 y)) :: Char -> Age. But this isn't good either, because eta exapansion isn't semantically valid (if x2 was bottom, seq could distinguish the two). See #7542 for a real life example.

For x3, we'd have to map over T, thus mapT MkAge x3. But what if mapT didn't exist? We'd have to make it. And not all data types have maps. S is a harder one: you could only map over S-values if m was a functor. There's a lot of discussion abou this on #2110.

The proposal

Clearly what we want is a way to "lift" newtype constructors (and dually deconstructors)
over arbitrary types, so that whenever we have some type blah Int blah we can convert it
to the type blah Age blah, and vice versa.

The problem is, as usual, the type function hiding inside T's definition.
The solution is described in [​http://research.microsoft.com/en-us/um/people/simonpj/papers/ext-f/
Generative type abstraction and type-level computation]. It is still not implemented, alas,
but adding the newtype wrappers introduces no problems that we do not already have.