<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br></div><div>On Jun 17, 2017, at 20:43, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com">xiaodi.wu@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div>In Swift, all types and all operators are implemented in the standard library. How do you express the idea that, when you add values of disparate types T and U, the result should be of the type with greater precision? You need to be able to spell this somehow.</div>
</blockquote><br><div>Oh, ok... I thought you meant "conditional conformance" or something <i>concrete</i> :-D</div><div><br></div><div>Off the top of my head, with "literals as generic parameters",</div><div>protocol Addable {</div><div>&nbsp; associatedtype BitsOfPrecision: IntegerLiteral</div><div>&nbsp; static func + &lt;T: Addable&gt; (_: Self, _: T) -&gt; T where T.<span style="background-color: rgba(255, 255, 255, 0);">BitsOfPrecision &gt;</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">BitsOfPrecision</span></div><div><div><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; static func + &lt;T: Addable&gt; (_: Self, _: T) -&gt; Self where T.BitsOfPrecision &lt;=&nbsp;</span><span style="background-color: rgba(255, 255, 255, 0);">BitsOfPrecision</span></div></div><div><span style="background-color: rgba(255, 255, 255, 0);">}</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">Although, come to think of it, I suppose that's a bit more than simply using literals as types. Still, it's all information that's available at compile time, though.</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">- Dave Sweeris&nbsp;</span></div></body></html>