newtype has come up again and since I don't have a specific pitch I thought I'd start some discussion outside of the older thread. Before diving into specific syntax or implementation details I think it would be good to gather ideas about what people want out of such a feature and what they feel is most important.
Personally, I'm a fan of starting with simpler
newtypes inherit all of the functionality and conformances of the original type, but are considered separate types. Developers could add additional functionality and protocol conformances but couldn't override any. It would also be useful if these simple
newtypes were covariant with their original types, but I'm not sure what the overall impact would be there. To my mind, this is a useful feature on its own, even given its limited nature.
If we wanted to go further, perhaps extensions could be used to override protocol conformances, as those are usually self contained. However, there may be other issues around some of the original type's conformances depending on overridden conformances. So perhaps if you override a dependent conformance you have to override whatever depends on it? (e.g. If you want custom
Sequence behavior, you'll need to override the
Collection implementation as well to use your new conformance.) I think these overrides would still be covariant with the original type since no API surface has been removed.
If we cared more about customizing which protocols the
newtypes conform to and don't care about losing covariance, it seems likely that explicitly listing the conformances we want, either as part of the declaration or as extensions that don't implement anything, would be an easy way to accomplish that. This would allow developers to pick and choose which conformances from a type they want. I'm not sure what a great motivating example would be for this aspect of the feature, anyone have ideas?
Two aspects of
newtypes I'm most unsure about are the overriding or removal of non-conformance API. Given the internal dependence on many of these APIs it seems likely it would be very difficult or dangerous to allow arbitrary overrides (though that may also be true of protocol conformances as well). Similarly, I'm also not sure the probable verbosity of any feature controlling the visiblity of particular APIs would hold its weight.