<div dir="ltr">From Brent’s explanation, it sounds to me like “Type” and “StaticType” respectively would be more descriptive than “Subtype” and “Type” as proposed.<div><br></div><div>Nevin</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 29, 2016 at 10:29 PM, Brent Royal-Gordon via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">> On Sep 29, 2016, at 3:24 PM, Russ Bishop via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
><br>
> Why would we not have type(of:) and subtype(of:)? Why would I want the Subtype<T> instead of the specific Type<T>?<br>
<br>
</span>Let's turn this around. Suppose you write:<br>
<br>
let obj: NSObject = …<br>
let ty = type(of: obj)<br>
<br>
What is `ty`? Well, it's a `Type<NSObject>`, and there's only one of those: `NSObject.self`. So there's only one possible instance that could be assigned to that variable.<br>
<br>
This is true in general: If `type(of:)` returns `Type<T>`, then it can only have one possible return value. In other words, the return value of `type(of:)` would always be the *static* type of the variable, not its dynamic type. There may be some narrow cases where that'd be useful, but 99% of the time, you want `subtype(of:)` because you're trying to discover which of many dynamic subtypes of the static type you're actually dealing with. So most uses of `type(of:)` would probably be mistaken attempts to perform `subtype(of:)` instead.<br>
<span class=""><br>
> What is the rationale for losing the meta type relationships by having Type<U> not be a subtype of Type<T>?<br>
<br>
</span>The relationships aren't lost; they're just expressed through `Subtype`, not `Type`.<br>
<br>
Again, turn this around. `Subtype` is the normal thing that you'll want to use most of the time. `Type` is the weird thing whose existence is hard to explain. (One version of this proposal used `Type` for `Subtype` and `ExactType` for `Type` in order to imply that subtype is usually what you want, but some of the contributors weren't happy with that.)<br>
<br>
So, `Type` is the weird thing. Why does it exist? Two reasons:<br>
<br>
1. `Subtype<T>` only includes *inheritable* type members of `T`. `Type<T>` also includes *non-inheritable* members, particularly non-required initializers.<br>
<br>
2. It allows precise type matches: `subty is Subtype<NSObject>` would match for any subtype of `NSObject`, whereas `subty is Type<NSObject>` would only match for `NSObject` itself.<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Brent Royal-Gordon<br>
Architechies<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
</div></div></blockquote></div><br></div>