[swift-evolution] floating point numbers implicit conversion

Xiaodi Wu xiaodi.wu at gmail.com
Sat Jun 17 23:18:46 CDT 2017


And, without integer literals as generic parameters, how would you express
this operation?


On Sat, Jun 17, 2017 at 23:01 David Sweeris <davesweeris at mac.com> wrote:

>
> On Jun 17, 2017, at 20:43, Xiaodi Wu <xiaodi.wu at gmail.com> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170618/34946b76/attachment.html>


More information about the swift-evolution mailing list