[swift-evolution] [Pitch] Refactor Metatypes

Adrian Zubarev adrian.zubarev at devandartist.com
Sat Feb 18 10:55:31 CST 2017

The problem I was describing is about nested types named .Type, indeed. Assuming the proposal would go with Type<T>, then it means you _might_ be able to create nested types called Type, but you always would need to call if through the whole namespace (e.g. A.B.Type). That is a huge downside.

Metatype on the other hand describes exactly what that _thing_ really is.

Currently on a different branch I added this important note to the alternatives, but I’d rather use these types for the whole proposal.

Assuming that the accepted proposal decides to use Metatype<T>, AnyMetatype<T> over Type<T> and AnyType<T> would imply that the type Type would no longer be ambiguous to use in custome modules. However, such naming choice will affect the type(of:) function. It might be necessary to align the function name to metatype(of:) to avoid any confusion, which will result in another breaking change. Alternatively we could leave the function as func type<T>(of instance: T) -> AnyMetatype<T>.
If we’re going for breaking changes again than I’d prefer to align the magical type(of:) function to metatype(of:).

I’d love to hear more input on this.

Adrian Zubarev
Sent with Airmail

Am 18. Februar 2017 um 17:00:27, Anton Zhilin (antonyzhilin at gmail.com) schrieb:

Type is a bad name for a public type:  
FooType is almost always a better name. Libraries that describe “just types”, Swift types, can as well use  
Metatype or  
Mirror or something.
For nested types, like  
Foo.Type, in the meaning of “type of  
Type can’t be used even now.
I’d give up on  
Type name for the greater future of metatypes.

2017-02-18 16:28 GMT+03:00 Adrian Zubarev <adrian.zubarev at devandartist.com>:

Personally I’d prefer Metatype<T> and AnyMetatype<T> to get rid of the restriction where you mostly cannot create custom types called Type, which annoys me a lot. Sometimes Kind as a good workaround but there are times where Kind doesn’t fit. :/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170218/1982f4eb/attachment.html>

More information about the swift-evolution mailing list