[swift-evolution] [Discussion] Seal `T.Type` into `Type<T>`

Anton Zhilin antonyzhilin at gmail.com
Fri Jul 15 14:49:26 CDT 2016

I suggested it because now we can’t call any initializers on Type<T>. If we
add _Type<T>, we can add public initializers and keep Type<T> instances

// No uniqueness guarantee
internal final class _Type<T> {
    var _metatype: Metatype<T>

    init(_: AnyMetatype)
    init?<U>(casting: Type<U>)

internal var _typeStorage = Set<_Type<Any>>()
// Uniqueness guarantee// 'final class' is an implementation detail
public struct Type<T> {
    internal var _impl: _Type<T>

    // Notice 'public'
    public init()
    public init(_: AnyMetatype)
    public init?<U>(casting: Type<U>)

There will be no === operator for Type<T>, because it does not add value.
Type<T> is a wrapper of typeless identifier with value semantics. It is
singleton pattern that makes us use classes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160715/29416e08/attachment.html>

More information about the swift-evolution mailing list