[swift-evolution] ExpressibleByZeroLiteral

Sasha Lopoukhine sasha.swi.evo at gmail.com
Fri Mar 31 11:31:14 CDT 2017


Completely forgot about those. Thank you. The point still stands, it doesn't really make sense to multiply strides by each other. I don't know how this would work, but if we're already ok to shake up the Integer protocols, then maybe adding one between SignedNumeric and SignedInteger might be ok.


> On 31 Mar 2017, at 17:25, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
> 
> Have you seen the revised integer protocols?
> https://github.com/apple/swift-evolution/blob/master/proposals/0104-improved-integers.md <https://github.com/apple/swift-evolution/blob/master/proposals/0104-improved-integers.md>
> 
> `SignedNumeric` will no longer refine `Comparable`. It will, however, still require that you can define multiplication.
> 
> 
> On Fri, Mar 31, 2017 at 11:09 AM, Sasha Lopoukhine via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> Hello everyone!
> 
> I'd like to discuss the constraint on Strideable. I see no reason to restrict Strideable types to non-circular types. It would be pretty neat/useful to be able to define a type such as a Week, with strides looping around to the start of the enum. Currently, the only reason this is impossible is because of the restriction on Stride that it must conform to SignedNumber.
> 
> I think that it might be worth looking into defining a new protocol specifically for the constraint on Strideable.Stride, something that looks like this:
> 
> /// Instances of conforming types can be subtracted, arithmetically
> /// negated, and initialized from `0`.
> ///
> /// Axioms:
> ///
> /// - `x - 0 == x`
> /// - `-x == 0 - x`
> /// - `-(-x) == x`
> public protocol StrideProtocol : ExpressibleByIntegerLiteral {
> 
>     /// Returns the result of negating `x`.
>     prefix public static func -(x: Self) -> Self
> 
>     /// Returns the difference between `lhs` and `rhs`.
>     public static func -(lhs: Self, rhs: Self) -> Self
> }
> 
> public typealias SignedNumber = StrideProtocol & Comparable
> 
> Strideable.Stride could then conform to StrideProtocol, allowing groups etc. 
> 
> WDYT?
> 
> -- Sasha
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170331/e483931e/attachment.html>


More information about the swift-evolution mailing list