<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">It reminds me of "Refinement Types" (see for example [this blog post][1] or [this paper][2]). </div><div class=""><br class=""></div><div class="">I generally think it’s a cool idea and that it can be useful in minimizing partial functions by requiring that these cases are explicitly handled. </div><div class="">For example, highlighting that the following `average` implementation divides by zero when the list is empty:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">func average(numbers: [Int]) -> Int {</div><div class=""> return sum(numbers) / numbers.count</div><div class="">}</div></blockquote><div class=""><br class=""></div><div class="">and requiring that the empty list case is handled separately:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">func average(numbers: [Int]) -> Int {</div><div class=""> guard !numbers.isEmpty else { return 0 }</div><div class=""> return sum(numbers) / numbers.count</div><div class="">}</div></blockquote><div class=""><br class=""></div><div class="">Regards,</div><div class="">David</div><div class=""><br class=""></div><div class="">[1]: <a href="http://goto.ucsd.edu/~rjhala/liquid/haskell/blog/blog/2013/01/01/refinement-types-101.lhs/" class="">http://goto.ucsd.edu/~rjhala/liquid/haskell/blog/blog/2013/01/01/refinement-types-101.lhs/</a></div><div class="">[2]: <a href="http://goto.ucsd.edu/~nvazou/refinement_types_for_haskell.pdf" class="">http://goto.ucsd.edu/~nvazou/refinement_types_for_haskell.pdf</a></div><div class=""><br class=""></div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On 11 May 2016, at 20:00, Adrian Zubarev via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class="">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; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class="">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<-1.0 … 1.0>.</div><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div id="bloop_sign_1462989326730136832" class="bloop_sign" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="font-family: helvetica, arial; font-size: 13px;" class="">-- <br class="">Adrian Zubarev<br class="">Sent with Airmail</div></div><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><p class="airmail_on" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Am 11. Mai 2016 bei 19:54:09, Matthew Johnson (<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>) schrieb:</p><blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class=""><div dir="auto" class=""><div class=""></div><div class=""><div class="">This is called a refinement type. It would be cool to explore that direction in the future but it is definitely well out of scope for Swift 3.<br class=""><br class="">Sent from my iPad</div><div class=""><br class="">On May 11, 2016, at 12:45 PM, Adrian Zubarev via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><div id="bloop_customfont" style="margin: 0px;" class="">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;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">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;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">func foo(value: Int) {</div><div id="bloop_customfont" style="margin: 0px;" class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">assert(value > 0 && value <= 10)</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">// passed</div><div id="bloop_customfont" style="margin: 0px;" class="">}</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">How would it be if Swift would allow us to constraint numeric typs with ranges/intervals?</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">func newFoo(value: Int<1...10>) {</div><div id="bloop_customfont" style="margin: 0px;" class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">// no need for an assertion any more</div><div id="bloop_customfont" style="margin: 0px;" class="">}</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">We could go even further and add more then one range/interval:</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">func someFoo(value: Int<0...20, 40...60>) { /* do some work */ }</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">Not only integers should have this ability but also floating point types like Double and Float. </div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">Alternative form might look like this:</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">Double[1.0...10.0]</div><div id="bloop_customfont" style="margin: 0px;" class="">Float[0.0...1.0, 10.0...100.0]</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">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;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">1...10 means 1..<11 equals [1, 11)</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">But how can we create something like (0.0, 1.0), do we need a strange looking binary operator 0.0>..<1.0?</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">What do you think? I'd love to hear any feedback to this.</div></div><br class=""><div id="bloop_sign_1462988584784969984" class="bloop_sign"><div style="font-family: helvetica, arial; font-size: 13px;" class="">-- <br class="">Adrian Zubarev<br class="">Sent with Airmail</div></div></div></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote></div></div></span></blockquote><span style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></body></html>