<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">Okay I’m fine with that for now. If you’d have to decide on some syntax for such a future, how would it look like? I’m just curious.</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">I tend to square brackets Double[0.0 … 1.0], because otherwise it might look like a generic type, but I’m not sure if this type refinement could be applied to other types as well so we actually would stick to the generic type syntax here Float&lt;-1.0 … 1.0&gt;.</div> <br> <div id="bloop_sign_1462989326730136832" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">--&nbsp;<br>Adrian Zubarev<br>Sent with Airmail</div></div> <br><p class="airmail_on">Am 11. Mai 2016 bei 19:54:09, Matthew Johnson (<a href="mailto:matthew@anandabits.com">matthew@anandabits.com</a>) schrieb:</p> <blockquote type="cite" class="clean_bq"><span><div dir="auto"><div></div><div>




<title></title>


<div>This is called a refinement type. &nbsp;It would be cool to
explore that direction in the future but it is definitely well out
of scope for Swift 3.<br>
<br>
Sent from my iPad</div>
<div><br>
On May 11, 2016, at 12:45 PM, Adrian Zubarev via swift-evolution
&lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;
wrote:<br>
<br></div>
<blockquote type="cite">
<div>
<div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">
<div id="bloop_customfont" style="margin: 0px;">Hello Swift
community. I'd like to discuss with you if we need something like
this in Swift 3 or any future Swift version.</div>
<div id="bloop_customfont" style="margin: 0px;"><br></div>
<div id="bloop_customfont" style="margin: 0px;">As you may know
there is no way to constrain a numeric type expect for some scope
internal assertion or precodintions which may produce a runtime
error if the input value is out of the defined bound.</div>
<div id="bloop_customfont" style="margin: 0px;"><br></div>
<div id="bloop_customfont" style="margin: 0px;">func foo(value:
Int) {</div>
<div id="bloop_customfont" style="margin: 0px;"></div>
<div id="bloop_customfont" style="margin: 0px;">assert(value &gt; 0
&amp;&amp; value &lt;= 10)</div>
<div id="bloop_customfont" style="margin: 0px;"><br></div>
<div id="bloop_customfont" style="margin: 0px;">// passed</div>
<div id="bloop_customfont" style="margin: 0px;">}</div>
<div id="bloop_customfont" style="margin: 0px;"><br></div>
<div id="bloop_customfont" style="margin: 0px;">How would it be if
Swift would allow us to constraint numeric typs with
ranges/intervals?</div>
<div id="bloop_customfont" style="margin: 0px;"><br></div>
<div id="bloop_customfont" style="margin: 0px;">func newFoo(value:
Int&lt;1...10&gt;) {</div>
<div id="bloop_customfont" style="margin: 0px;"></div>
<div id="bloop_customfont" style="margin: 0px;">// no need for an
assertion any more</div>
<div id="bloop_customfont" style="margin: 0px;">}</div>
<div id="bloop_customfont" style="margin: 0px;"><br></div>
<div id="bloop_customfont" style="margin: 0px;">We could go even
further and add more then one range/interval:</div>
<div id="bloop_customfont" style="margin: 0px;"><br></div>
<div id="bloop_customfont" style="margin: 0px;">func someFoo(value:
Int&lt;0...20, 40...60&gt;) { /* do some work */ }</div>
<div id="bloop_customfont" style="margin: 0px;"><br></div>
<div id="bloop_customfont" style="margin: 0px;">Not only integers
should have this ability but also floating point types like Double
and Float.&nbsp;</div>
<div id="bloop_customfont" style="margin: 0px;"><br></div>
<div id="bloop_customfont" style="margin: 0px;">Alternative form
might look like this:</div>
<div id="bloop_customfont" style="margin: 0px;"><br></div>
<div id="bloop_customfont" style="margin: 0px;">
Double[1.0...10.0]</div>
<div id="bloop_customfont" style="margin: 0px;">Float[0.0...1.0,
10.0...100.0]</div>
<div id="bloop_customfont" style="margin: 0px;"><br></div>
<div id="bloop_customfont" style="margin: 0px;">One downside of
half opened ranges/intervals is the left side of its set. How do we
exclude the left element?</div>
<div id="bloop_customfont" style="margin: 0px;"><br></div>
<div id="bloop_customfont" style="margin: 0px;">1...10 means
1..&lt;11 equals [1, 11)</div>
<div id="bloop_customfont" style="margin: 0px;"><br></div>
<div id="bloop_customfont" style="margin: 0px;">But how can we
create something like (0.0, 1.0), do we need a strange looking
binary operator 0.0&gt;..&lt;1.0?</div>
<div id="bloop_customfont" style="margin: 0px;"><br></div>
<div id="bloop_customfont" style="margin: 0px;">What do you think?
I'd love to hear any feedback to this.</div>
</div>
<br>
<div id="bloop_sign_1462988584784969984" class="bloop_sign">
<div style="font-family:helvetica,arial;font-size:13px">
--&nbsp;<br>
Adrian Zubarev<br>
Sent with Airmail</div>
</div>
</div>
</blockquote>
<blockquote type="cite">
<div>
<span>_______________________________________________</span><br>
<span>swift-evolution mailing list</span><br>
<span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br>

<span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br>
</div>
</blockquote>


</div></div></span></blockquote></body></html>