<div dir="ltr">This is mentioned in the Generics Manifesto as &quot;Conditional Conformances via Protocol Extensions&quot;: &lt;<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>&gt;<div><br></div><div>While it would be a very powerful and useful feature, it&#39;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&#39;s a good discussion about it on the list that&#39;s better than anything I could write: &lt;<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>&gt;</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 &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; 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) -&gt; 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>