[swift-evolution] [Pitch] Remove type inference for associated types

Douglas Gregor dgregor at apple.com
Tue Jun 28 23:51:06 CDT 2016


> On Jun 28, 2016, at 9:45 PM, Paulo Faria <paulo at zewo.io> wrote:
> 
> 
>> On Jun 28, 2016, at 3:34 PM, Matthew Johnson via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>>>> Finally, I am very concerned that there are protocols such as Collection,
>>>> with many inferrable associated types, and that conforming to these
>>>> protocols could become *much* uglier.
> 
> Unfortunately I have a specific use case in which this argument would be very strong.
> 
> Basically this:
> 
> extension TodoController : ResourceController {}
> 
> Would have to become this:
> 
> extension TodoController : ResourceController {
>     public typealias CreateInput = Todo
>     public typealias UpdateInput = Todo
> 
>     public typealias ListOutput = Todo
>     public typealias CreateOutput = Todo
>     public typealias DetailOutput = Todo
>     public typealias UpdateOutput = Todo
> 
>     public typealias DetailID = String
>     public typealias UpdateID = String
>     public typealias DestroyID = String
> }
> 
> I could reduce the amount of associated types but this would reduce the flexibility of the protocol by a huge factor and would make it much less powerful. I’m very torn about this because I do want generics to get better. Specifically I’m looking forward to conditional conformances. But this would be a too high cost imho. I know this is just one example. But maybe there are more examples like this out there. I have to admit this one really got to me. :(


Do these associated types have meaningful defaults? We’re not talking about eliminating the ability to have default types for associated types, e.g.,

	public protocol ResourceController {
	  associatedtype CreateInput
	  associatedtype UpdateInput = CreateInput

	  associatedtype ListOutput
	  associatedtype CreateOutput = ListOutput
	  associatedtype DetailOutput = ListOutput
	  associatedtype UpdateOutput = ListOutput

	  associatedtype DetailID
	  associatedtype UpdateID = DetailID
	  associatedtype DestroyID = DetailID
	}

which might reduce the common case for conforming to the protocol to be, e.g.,

	extension TodoController : ResourceController {
	  public typealias CreateInput = Todo
	  public typealias ListOutput = Todo
	  public typealias DetailID = String
	}

	- Doug

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160628/0ded92e6/attachment.html>


More information about the swift-evolution mailing list