> On Jun 29, 2016, at 1:51 AM, Douglas Gregor <dgre...@apple.com> wrote: > > 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
Unfortunately no. The whole purpose of having so many associated types is that the user can simply chose the types he wants to use as the input and output of each function required in the protocol. public protocol ResourceController { associatedtype CreateInput: StructuredDataInitializable associatedtype UpdateInput: StructuredDataInitializable associatedtype ListOutput: StructuredDataFallibleRepresentable associatedtype CreateOutput: StructuredDataFallibleRepresentable associatedtype DetailOutput: StructuredDataFallibleRepresentable associatedtype UpdateOutput: StructuredDataFallibleRepresentable associatedtype DetailID: PathParameterInitializable associatedtype UpdateID: PathParameterInitializable associatedtype DestroyID: PathParameterInitializable func list() throws -> [ListOutput] func create(element: CreateInput) throws -> CreateOutput func detail(id: DetailID) throws -> DetailOutput func update(id: UpdateID, element: UpdateInput) throws -> UpdateOutput func destroy(id: DestroyID) throws }
_______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution