<div dir="ltr">This is mentioned in the Generics Manifesto as "Conditional Conformances via Protocol Extensions": <<a href="https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#conditional-conformances-via-protocol-extensions">https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#conditional-conformances-via-protocol-extensions</a>><div><br></div><div>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: <<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160905/027032.html">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160905/027032.html</a>></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Sep 22, 2017 at 1:53 PM Nevin Brackett-Rozinsky via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">With Swift 4 out, I’ve started using the numeric protocols quite a bit, and they are great!<div><br></div><div>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.</div><div><br></div><div>Absent a Field protocol in the standard library, I can create one of my own:<br><div><br></div><div><div><font face="monospace, monospace">protocol Field: Numeric {</font></div><div><font face="monospace, monospace"> static func / (lhs: Self, rhs: Self) -> Self</font></div><div><font face="monospace, monospace">}</font></div></div><div><br></div><div>And I can extend Float and Double and Float80 to conform easily enough. However, I’d really like to write,</div></div><div><br></div><div><font face="monospace, monospace">extension FloatingPoint: Field {}</font></div><div><br></div><div>and make every type which conforms to FloatingPoint (such as a third-party Complex type), also conform to Field.</div><div><br></div><div>Is this potentially feasible? Would other people find it useful?</div><div><br></div><div>Nevin</div></div>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>