[swift-evolution] [Pitch] Extend Any.Type to allow construction of bound generic types

Howard Lovatt howard.lovatt at gmail.com
Sun Apr 17 17:50:58 CDT 2016


I would also find this useful, should this be part of completing generics?

On Monday, 18 April 2016, Joanna Carter via swift-evolution <
swift-evolution at swift.org> wrote:

> I often find myself needing to construct an instance of a bound generic
> type at runtime, in much the same manner as I would a "standard" type.
>
> e.g.
>
> As for a standard type…
>
> let aType = Int.Type
>
> let anInt = aType.init(0)
>
> I also want to be able to use the same mechanism for a generic type…
>
> struct MyStruct<T: Equatable /*, etc */>
> {
>   var value: T?
> }
>
> let paramType = // type from streaming or reflection compliant with
> Equatable
>
> let structType = MyStruct<paramType>.self
>
> let f = structType.init()
>
>
> At present, the following compiler error is raised…
>
> 'paramType' is not a type
>
> I am  the only one to require this behaviour? If not, do we want a
> proposal? If so, could you let me know your views on its worthiness?
>
> Joanna
>
> --
> Joanna Carter
> Carter Consulting
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <javascript:;>
> https://lists.swift.org/mailman/listinfo/swift-evolution
>


-- 
-- Howard.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160418/b5f5a1f6/attachment.html>


More information about the swift-evolution mailing list