<div dir="ltr"><i>For what it's worth, I believe the pull request Anton mentioned above (<<a href="https://github.com/apple/swift-evolution/pull/553" rel="noreferrer" class="gmail_msg" target="_blank">https://github.com/apple/swift-evolution/pull/553</a>>) addresses this.</i><br><div><br></div><div><br></div><div>And this proposal is suggesting moving away from the pattern/practice, rather than diving deeper into it. They are, therefore, (unintentionally) antagonistic.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Sun, 4 Dec 2016 at 21:56 Brent Royal-Gordon via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> On Dec 1, 2016, at 2:09 PM, Dave Abrahams via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:<br class="gmail_msg">
><br class="gmail_msg">
> More<br class="gmail_msg">
> importantly, they suggest that the metatype argument will be used in<br class="gmail_msg">
> some dynamic way (e.g. by calling a static method or an init), instead<br class="gmail_msg">
> of just as a way to get the right type inference. In some cases that<br class="gmail_msg">
> can make a dramatic difference in the resulting semantics.<br class="gmail_msg">
><br class="gmail_msg">
> func polymorphicSomething<T>(_: T.Type) {<br class="gmail_msg">
> ...<br class="gmail_msg">
> }<br class="gmail_msg">
><br class="gmail_msg">
> class Base {}<br class="gmail_msg">
> class Derived : Base {}<br class="gmail_msg">
><br class="gmail_msg">
> func otherThing(x: Base) {<br class="gmail_msg">
> // Surprise! I'm going to ignore the dynamic type you gave me and<br class="gmail_msg">
> // just use Base<br class="gmail_msg">
> polymorphicSomething(type(of: y))<br class="gmail_msg">
> }<br class="gmail_msg">
><br class="gmail_msg">
> otherThing(Derived())<br class="gmail_msg">
<br class="gmail_msg">
For what it's worth, I believe the pull request Anton mentioned above (<<a href="https://github.com/apple/swift-evolution/pull/553" rel="noreferrer" class="gmail_msg" target="_blank">https://github.com/apple/swift-evolution/pull/553</a>>) addresses this. It provides both `Type<T>`, which means *exactly* T, and `AnyType<T>`, which means *any subtype of* `T`. You'd use `Type<T>` for type-pinning parameters and `AnyType<T>` for dynamically-typed parameters.<br class="gmail_msg">
<br class="gmail_msg">
(`AnyType<T>` is a protocol-like type which all `Type<_>`s for subtypes of `T` "conform" to. Thus, you can pass a `Type<T>` as an `AnyType<T>`, but not vice versa.)<br class="gmail_msg">
<br class="gmail_msg">
In other words, if `polymorphicSomething` were declared like:<br class="gmail_msg">
<br class="gmail_msg">
func polymorphicSomething<T>(_: AnyType<T>) {<br class="gmail_msg">
...<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
Then you would expect it to use the specific subtype you provided. But if you said:<br class="gmail_msg">
<br class="gmail_msg">
func polymorphicSomething<T>(_: Type<T>) {<br class="gmail_msg">
...<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
Then it would be clear in the signature that it was using only the static type of `T`, not the dynamic type. (It'd be clear because `Type<T>` can only contain `T`'s type instance, not subtypes' type instances.) Since `type(of:)` would return an `AnyType<Base>`, this line:<br class="gmail_msg">
<br class="gmail_msg">
polymorphicSomething(type(of: y))<br class="gmail_msg">
<br class="gmail_msg">
Would be trying to pass `AnyType<Base>` to a `Type<_>` parameter, which would not fly. Thus, it would fail at compile time.<br class="gmail_msg">
<br class="gmail_msg">
--<br class="gmail_msg">
Brent Royal-Gordon<br class="gmail_msg">
Architechies<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>