[swift-evolution] ExpressibleByZeroLiteral
Sasha Lopoukhine
sasha.swi.evo at gmail.com
Fri Mar 31 11:09:54 CDT 2017
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170331/c2569a91/attachment.html>
More information about the swift-evolution
mailing list