[swift-evolution] Retroactive protocol inheritance

Tony Allevato tony.allevato at gmail.com
Fri Sep 22 16:06:43 CDT 2017

This is mentioned in the Generics Manifesto as "Conditional Conformances
via Protocol Extensions": <

While it would be a very powerful and useful feature, it's apparently also
very difficult unfortunately :(  One of the biggest issues with
implementing it would be the effects that is has on dynamic type checking
for protocols, and there's a good discussion about it on the list that's
better than anything I could write: <

On Fri, Sep 22, 2017 at 1:53 PM Nevin Brackett-Rozinsky via swift-evolution
<swift-evolution at swift.org> wrote:

> With Swift 4 out, I’ve started using the numeric protocols quite a bit,
> and they are great!
> One thing I find myself wishing for is a protocol that extends Numeric
> while also allowing division—a Field protocol, if you will. I have
> implemented several algorithms generically over FloatingPoint because they
> need division, which means they aren’t available for, eg., a Rational type.
> Absent a Field protocol in the standard library, I can create one of my
> own:
> protocol Field: Numeric {
>   static func / (lhs: Self, rhs: Self) -> Self
> }
> And I can extend Float and Double and Float80 to conform easily enough.
> However, I’d really like to write,
> extension FloatingPoint: Field {}
> and make every type which conforms to FloatingPoint (such as a third-party
> Complex type), also conform to Field.
> Is this potentially feasible? Would other people find it useful?
> Nevin
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170922/0940bc72/attachment.html>

More information about the swift-evolution mailing list