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

Paulo Faria paulo at zewo.io
Tue Jun 28 23:55:23 CDT 2016


> On Jun 29, 2016, at 1:51 AM, Douglas Gregor <dgregor at 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
}



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


More information about the swift-evolution mailing list