on Fri Jun 09 2017, Matthew Johnson <swift-evolution@swift.org> wrote:
>> On Jun 9, 2017, at 12:09 PM, Xiaodi Wu via swift-evolution >> <swift-evolution@swift.org> wrote: >> >> On Fri, Jun 9, 2017 at 12:44 Robert Bennett via swift-evolution >> <swift-evolution@swift.org > >> <mailto:swift-evolution@swift.org>> >> wrote: >> Somewhat related to this, shouldn’t it be possible to sub-struct a >> struct as long as you only add functions and computed properties >> (i.e., no stored properties)? Traditionally structs cannot be >> subtyped because their size must be known at compile time. I don’t >> know the implementation details of where functions and computed >> properties live, but something tells me they belong to the type and >> not the object (although I’ve never really made the effort to sit >> down and fully understand Swift’s type model), in which case adding >> them to a struct’s definition would not change the size of the >> object on the stack. Thus it should be possible to make custom >> substructs of String that add additional functionality but no new >> stored properties. Thoughts? >> >> Value subtyping is a large subject and, IIUC, newtype would be a >> subset of that topic. Unlikely to be in scope for Swift 5, though, >> but that’s up to the core team. > > I see newtype as being more related to forwarding than subtyping. > Usually you want to hide significant parts of the interface to the > wrapped type. Yes, and whether you want an implicit conversion relationship between the newtype and the old is an orthogonal issue. -- -Dave _______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution