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
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to