<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 <<a href="mailto:xiaodi.wu@gmail.com">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>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></body></html>