[swift-evolution] [Discussion] Generic protocols

Adrian Zubarev adrian.zubarev at devandartist.com
Fri Dec 2 11:37:18 CST 2016

Check out the thread called: How to rewrite this snippet without existentials?

On some classes I want to write something like this:

enum X {…}
enum Y {…}

class A : Connection<X>, Connection<Y> { … }

let a = A()

let router = Router<X>()

Adrian Zubarev
Sent with Airmail

Am 2. Dezember 2016 um 18:32:47, Daniel Leping (daniel at crossroadlabs.xyz) schrieb:

Could you, please, bring a code

On Fri, 2 Dec 2016 at 19:31 Adrian Zubarev <adrian.zubarev at devandartist.com> wrote:
The problem I bumped into is, that I cannot overload a function which uses an associated type, so I could pass that instance to different type which needs the other overloaded function. Only generic protocols could do this.

Something similar is described as the top of the Generic protocols section in the generics manifesto.

Adrian Zubarev
Sent with Airmail

Am 2. Dezember 2016 um 18:25:49, Daniel Leping (daniel at crossroadlabs.xyz) schrieb:

Aren't protocols generic already using

Also, what I really would like to have is generic associatedtype.
Basically to work the very same way as typealias.

Another nice to have feature might be having a possibility to add
the same generic protocol several times with different type
associated. It might be a bad C++ habit, though. Still I really
miss it sometimes :)

What else is missing for me is possibility to declare a var or
return type by generic protocol. Have to create a specific class
all the time which is a big pain.

On Fri, 2 Dec 2016 at 18:36 Adrian Zubarev via swift-evolution <swift-evolution at swift.org> wrote:
Hi there, I wanted to ask if we need generic protocols in stage one or is it something for stage two? I literally bumped into a corner where I need them to write a nice and type safe API.

Adrian Zubarev
Sent with Airmail
swift-evolution mailing list
swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161202/4504956b/attachment.html>

More information about the swift-evolution mailing list