[swift-users] How to add this generic static func as a protocol requirement?
Slava Pestov
spestov at apple.com
Fri Jul 7 11:49:09 CDT 2017
Try using an associated type for the result of foo():
protocol P {
associatedtype R
static func foo<T>(_ v: T) -> R
}
Slava
> On Jul 7, 2017, at 1:50 AM, Jens Persson via swift-users <swift-users at swift.org> wrote:
>
> protocol P {
> // …
> // For example the following will not work:
> // static func foo<T, R>(_ v: T) -> R
> // Is there some other way?
> // …
> }
> struct S2 : P {
> static func foo<T>(_ v: T) -> (T, T) {
> return (v, v)
> }
> }
> struct S3 : P {
> static func foo<T>(_ v: T) -> (T, T, T) {
> return (v, v, v)
> }
> }
>
> (I'm guessing but am not sure that I've run into (yet) a(nother) situation which would require higher kinded types?)
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
More information about the swift-users
mailing list