
On Tue, Aug 26, 2008 at 1:19 AM, wren ng thornton
It should also be noted that the overhead for newtypes is not *always* removed. In particular, if we have the following definitions:
data Z = Z newtype S a = S a
We must keep the tags (i.e. boxes) for S around because (S Z) and (S (S Z)) need to be distinguishable. This only really comes up with polymorphic newtypes (since that enables recursion), and it highlights the difference between strict fields and unpacked strict fields. Typically newtypes are unpacked as well as strict (hence no runtime tag overhead), but it's not guaranteed.
Is this true? (S Z) and (S (S Z)) only need to be distinguished during typechecking. This would be different if it was some sort of existential type:
newtype N = forall a. Num a => N a but GHC at least disallows existential boxes in newtypes.
-- ryan