<div>And, without integer literals as generic parameters, how would you express this operation?</div><div><br></div><div><br><div class="gmail_quote"><div>On Sat, Jun 17, 2017 at 23:01 David Sweeris <<a href="mailto:davesweeris@mac.com">davesweeris@mac.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><br></div><div>On Jun 17, 2017, at 20:43, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>> 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><div><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> associatedtype BitsOfPrecision: IntegerLiteral</div><div> static func + <T: Addable> (_: Self, _: T) -> T where T.<span style="background-color:rgba(255,255,255,0)">BitsOfPrecision ></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)"> static func + <T: Addable> (_: Self, _: T) -> Self where T.BitsOfPrecision <= </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 </span></div></div></blockquote></div></div>