Is there a need of having this function at all? You always know the current 
static type locally. Sure one might need this in some generic function to 
extract the static type from an instance, but most of the time we could just 
write T.self to do that.

If there really is a need for that function, we could move it to future talk 
when might want to add the following function to the language.

/// This function could find dynamically metatypes if they exist (even value 
func type/subtype<T>(of type: Type<T>, named name: String) -> AnyType<T>? { … }

protocol P { init() }
struct S : P { init() {} }

let struct: P = subtype(of: P.self, named: "S")!.init() // Neat
struct is S //=> true

// One day when `.self` magic is removed, we'd have this nice form.

let struct: P = subtype(of: P, named: "S")!.init() // Neat

// With the proposed metatype model we could even get the static metatypes for 

let protocolMetatype: AnyType<Any> = subtype(of: Any.self, named: "P")!
protocolMetatype is Type<P>    //=> true
protocolMetatype is AnyType<P> //=> false
Again this is something for the future, but I felt like I had to mention it.

I’ll fix the typo, thanks.

Adrian Zubarev
Sent with Airmail

Am 13. Oktober 2016 um 07:09:04, Russ Bishop ( schrieb:

Are we not going to have func staticType<T>(of instance: T) -> Type<T> ?

(Also you mis-spelled “instace”)

Overall I like it and the whole scheme brings some nice clarity.

swift-evolution mailing list

Reply via email to