[swift-evolution] Proposal: Allow explicit type parameter specification in generic function call

Haravikk swift-evolution at haravikk.me
Tue Nov 22 02:40:12 CST 2016


> On 22 Nov 2016, at 04:18, Ramiro Feria Purón via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Thanks Dave!
> 
> As another example, consider it as part of this common pattern:
> 
> class A<T> {
>     init() {
>         // ..
>     }
> }
> 
> class B<T>: A<T> {
>     override init() {
>         // ..
>     }
> }
> 
> class Factory {
>     
>     class func makeA<T>() -> A<T> { return B<T>() }
>     //..
> }
> 
> Factory.makeA<Int>()

You can still do this using one of the following:

	class Factory {
		class func makeA<T>(_ theType:T.Type) -> A<T> { return B<T>() }
	}
	let foo = Factory.makeA(Int.self)

	class Factory<T> {
		class func makeA() -> A<T> { return B<T>() }
	}
	let foo = Factor<Int>.makeA()

i.e- we already have the tools to do this; in the form of inference, passing the type, and adding the generic to the type itself. I guess I'm just not seeing a clear advantage that the proposed syntax adds except to allowing dropping of .self on the pass-the-type form of call.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161122/599286ad/attachment.html>


More information about the swift-evolution mailing list