Hi Ben,

The reason to include init?<T : BinaryInteger>(exactly:T) as a requirement for 
the Arithmetic (now Number) protocol was that it already refines 
ExpressibleByIntegerLiteral, so it would be quite weird to *not* allow explicit 
initialization.

Generic conversion to floating point types is not covered by this proposal, but 
is somewhat related:
https://github.com/apple/swift/blob/master/stdlib/public/core/FloatingPoint.swift.gyb#L257
 
<https://github.com/apple/swift/blob/master/stdlib/public/core/FloatingPoint.swift.gyb#L257>
https://github.com/apple/swift/blob/master/stdlib/public/core/FloatingPoint.swift.gyb#L1588
 
<https://github.com/apple/swift/blob/master/stdlib/public/core/FloatingPoint.swift.gyb#L1588>
There are a few unimplemented (but planned) initializers on FloatingPoint and 
BinaryFloatingPoint that would make this happen.
If and when those are implemented, you would be able to write the version of 
numericCast<I : BinaryInteger, F : BinaryFloatingPoint>() using those.

Hope this answers your question.

Max

> On Jan 17, 2017, at 9:43 AM, Ben Rimmington <m...@benrimmington.com> wrote:
> 
> <https://gist.github.com/moiseev/62ffe3c91b66866fdebf6f3fcc7cad8c>
> 
>       public protocol Arithmetic {
>         init?<T : BinaryInteger>(exactly source: T)
>       }
> 
>       public protocol BinaryInteger : Arithmetic {
>         init?<T : FloatingPoint>(exactly source: T)
>       }
> 
> Should the `init?(exactly:)` initializers belong to the same protocol?
> Would this allow generic conversions between integer and floating-point types?
> For example, a failable `numericCast` function.
> 
> -- Ben
> 

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to