And, without integer literals as generic parameters, how would you express this operation?
On Sat, Jun 17, 2017 at 23:01 David Sweeris <[email protected]> wrote: > > On Jun 17, 2017, at 20:43, Xiaodi Wu <[email protected]> wrote: > > 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. > > > Oh, ok... I thought you meant "conditional conformance" or something > *concrete* :-D > > Off the top of my head, with "literals as generic parameters", > protocol Addable { > associatedtype BitsOfPrecision: IntegerLiteral > static func + <T: Addable> (_: Self, _: T) -> T where T.BitsOfPrecision > > > BitsOfPrecision > static func + <T: Addable> (_: Self, _: T) -> Self where > T.BitsOfPrecision <= BitsOfPrecision > } > > 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. > > - Dave Sweeris >
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
