[swift-evolution] struct subtyping

Tino Heth 2th at gmx.de
Thu Mar 24 12:34:58 CDT 2016


> struct Object {
> let identifier: String
> }
> 
> struct User: Object {
> 
> }
> 
> struct Tree: Object {
> }
> 
> The last two structs get the identifier property "mixed" in but are unique types :)

Is unique meant so that User-Objects can't be used as "Object"-Object parameters?
I'm asking because this might be the biggest source of confusion with struct inheritance:
As the two "child-structs" don't add new data to their parent, they would (technically) be compatible — but this is fragile, so it might be preferable to "hide" polymorphism by default, and maybe add an annotation to explicitly allow that a sub-struct can be used as its parent type.
@compatible(Float) struct SpecialFloat: Float...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160324/113fc1bd/attachment.html>


More information about the swift-evolution mailing list