<div dir="ltr">Have you seen the revised integer protocols?<div><a href="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</a><br></div><div><br></div><div>`SignedNumeric` will no longer refine `Comparable`. It will, however, still require that you can define multiplication.</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 31, 2017 at 11:09 AM, Sasha Lopoukhine via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hello everyone!<div><br></div><div>I&#39;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.</div><div><br></div><div>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:</div><div><br></div><div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures">/// Instances of conforming types can be subtracted, arithmetically</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures">/// negated, and initialized from `0`.</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures">///</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures">/// Axioms:</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures">///</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures">/// - `x - 0 == x`</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures">/// - `-x == 0 - x`</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures">/// - `-(-x) == x`</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">public</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">protocol</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> StrideProtocol : </span><span style="font-variant-ligatures:no-common-ligatures">ExpressibleByIntegerLiteral</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> {</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;min-height:15px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures;color:#000000">    </span><span style="font-variant-ligatures:no-common-ligatures">/// Returns the result of negating `x`.</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures;color:#000000">    </span><span style="font-variant-ligatures:no-common-ligatures">prefix</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> </span><span style="font-variant-ligatures:no-common-ligatures">public</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> </span><span style="font-variant-ligatures:no-common-ligatures">static</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> </span><span style="font-variant-ligatures:no-common-ligatures">func</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> -(x: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Self</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">) -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Self</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;min-height:15px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures;color:#000000">    </span><span style="font-variant-ligatures:no-common-ligatures">/// Returns the difference between `lhs` and `rhs`.</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">static</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">func</span><span style="font-variant-ligatures:no-common-ligatures"> -(lhs: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Self</span><span style="font-variant-ligatures:no-common-ligatures">, rhs: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Self</span><span style="font-variant-ligatures:no-common-ligatures">) -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Self</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><span style="color:rgb(186,45,162)">public typealias </span></span>SignedNumber <span style="font-variant-ligatures:no-common-ligatures">= </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">StrideProtocol</span><span style="font-variant-ligatures:no-common-ligatures"> &amp; </span><span style="color:rgb(112,61,170);font-variant-ligatures:no-common-ligatures">Comparable</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;line-height:normal">Strideable.Stride could then conform to StrideProtocol, allowing groups etc. </div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal">WDYT?</div><span class="HOEnZb"><font color="#888888"><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal">-- Sasha</div><div style="margin:0px;line-height:normal"><br></div></font></span></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div></div>