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
···
On Jun 28, 2016, at 9:45 PM, Paulo Faria <paulo@zewo.io> wrote:
On Jun 28, 2016, at 3:34 PM, Matthew Johnson via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@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 = Todopublic typealias ListOutput = Todo
public typealias CreateOutput = Todo
public typealias DetailOutput = Todo
public typealias UpdateOutput = Todopublic 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. :(