<html><body><div class="_stretch"><span class="body-text-content"><br><br>--<br>J. Charles <br><br><blockquote type="cite" class="quoted-plain-text">Le 16 juin 2016 à 15:57, Jeremy Pereira <jeremy.j.pereira@googlemail.com> a écrit :</blockquote><blockquote type="cite" class="quoted-plain-text"><br></blockquote><blockquote type="cite" class="quoted-plain-text"><br></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text">On 15 Jun 2016, at 21:07, J. Charles N. MBIADA via swift-evolution <swift-evolution@swift.org> wrote:</blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text"><br></blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text">Hi Swift,</blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text"><br></blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text">Since the "removal" of curried function, I am looking for some elegant ways to work with partial functions (and reduce creation of closure and nested func for the developper).</blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text"><br></blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text">And now I am asking myself if it's not better to align operator's types to the arrow style instead of using tuple argument style.</blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text"><br></blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text">For example:</blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text">Why Int.multiplyWithOverflow's type is (Int, Int) -> (Int, overflow: Bool) instead of (Int -> Int) -> (Int, overflow: Bool)</blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><br></blockquote><blockquote type="cite" class="quoted-plain-text">That looks wrong to me. That says that Int.multiplyWithOverflow is a function that takes another function (of type (Int) -> Int) and returns a tuple.</blockquote><blockquote type="cite" class="quoted-plain-text"><br></blockquote>Function which takes a function require parenthesis as you showed up: (Int) -> Int I am saying that using this fact, we can bring back auto curried function by eliminating parenthesis.<br>Int -> Int -> Int will be interpreted as a func which permit to generate partial function when arguments are missing.<br><br><br><blockquote type="cite" class="quoted-plain-text">What you really want is a function that takes an Int and returns another function that takes an Int and returns the tuple i.e. its signature would look like this</blockquote><blockquote type="cite" class="quoted-plain-text"><br></blockquote><blockquote type="cite" class="quoted-plain-text">(Int) -> ((Int) -> (Int, Bool))</blockquote><blockquote type="cite" class="quoted-plain-text"><br></blockquote>This last one will be interpreted as a final function which need exactly one parameter to be valid when it's called.<br><br>Plus seeing the example below work show how things are not clear if programmers doesn't want to go in a deep understanding of the language.. But it works well...<br></span></div><div class="_stretch"><span class="body-text-content"><br data-mce-bogus="1"></span></div><div class="_stretch"><span class="body-text-content"><p class="p1"><span class="s1">func f(_ arg: (Int, Int)) -> Int { </span><span class="s1"><span class="Apple-converted-space"></span>return arg.0 + arg.1 } // type : </span>(Int, Int) -> Int</p><p class="p1"><span class="s1">f(4,5) // returns 9</span></p><p class="p1"><span class="body-text-content"><span class="s1"><p class="p1">f((4,56)) // returns 60</p><p class="p1"><span class="body-text-content"><span class="body-text-content"><span class="s1"><br data-mce-bogus="1"></span></span></span></p></span></span></p><p class="p1"><span class="s1">func g(_ arg: Int, _ a: Int) -> Int { </span><span class="s1"><span class="Apple-converted-space"> </span>return arg + a } // type : (Int, Int) -> Int</span></p><p class="p1"><span class="body-text-content"><span class="s1"><p class="p1">g(4, 5) // returns 9</p></span></span></p><p class="p1"><span class="s1">g((4,56)) // fails</span></p><p class="p1"><span class="body-text-content"><span class="s1"><meta charset="utf-8"><span style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;" data-mce-style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;">// Ok putting label could help to distinguish but </span><p class="p1" style="margin: -1px; padding-left: 1px; color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;" data-mce-style="margin: -1px; padding-left: 1px; color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><span class="s1">func f( a:Int,<span class="Apple-converted-space"> </span>b:Int) -> Int { return a + b } and </span>func h(_ arg: (a:Int, b:Int)) -> Int { return arg.0 + arg.1 } still has the same type</p><p class="p1" style="margin: -1px; padding-left: 1px; color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;" data-mce-style="margin: -1px; padding-left: 1px; color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><span class="body-text-content"><span class="body-text-content"><span class="s1"><br data-mce-bogus="1"></span></span></span></p></span></span></p><p class="p1">Clearifying this situation IMHO seem to me as complicated (maybe more) as clarifying Int -> Int -> Int. Explaining the lambda concept once should be sufficient to clarify this one. Explaining Tuple concept could not help to clarify the behavior of the example above.</p><p class="p1"><span class="body-text-content"><br data-mce-bogus="1"></span></p><br><blockquote type="cite" class="quoted-plain-text">If we assume -> is right associative we can simplify to</blockquote><blockquote type="cite" class="quoted-plain-text"><br></blockquote><blockquote type="cite" class="quoted-plain-text">(Int) -> (Int) -> (Int, Bool)</blockquote></span></div><div class="_stretch"><span class="body-text-content"><span><br data-mce-bogus="1"></span></span></div><div class="_stretch"><span class="body-text-content"><span>Chris proposal to enforce parenthesis around arguments could be the opportunity to use that syntax to distinct curried functions from the others. </span></span></div><div class="_stretch"><span class="body-text-content"><span>Then (Int) -> (Int) -> (Int, Bool) is valid and say that full implementation was handled by the developer since Int -> Int -> (Int, Bool) is valid too but some workaround could be handled by the compiler.</span></span></div><div class="_stretch"><span class="body-text-content"><span>Making these functions some how different in programmer's intent. </span></span></div><div class="_stretch"><span class="body-text-content"><span>fun f(a:Int, b:Int) -> Int { return (a/b, a%b != 0)} has type Int -> Int -> (Int, Bool)</span></span></div><div class="_stretch"><span class="body-text-content"><span>and h<span style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;" data-mce-style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;">(a:Int) -> Int { return { b:Int in return (a/b, a%b != 0)} } has type (Int) -> (Int -> (Int, Bool))</span></span></span></div><div class="_stretch"><span class="body-text-content"><span><span style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;" data-mce-style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;"><br data-mce-bogus="1"></span></span></span></div><div class="_stretch"><span class="body-text-content"><span><span style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;" data-mce-style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;">f(4, 5); f(4)(5) // OK</span></span></span></div><div class="_stretch"><span class="body-text-content"><span><span style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;" data-mce-style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;">h(4)(5) // OK</span></span></span></div><div class="_stretch"><span class="body-text-content"><span><span style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;" data-mce-style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;">h(4, 5) // fails, or why not works as well</span></span></span></div><div class="_stretch"><span class="body-text-content"><span><span style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;" data-mce-style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;"><br data-mce-bogus="1"></span></span></span></div><div class="_stretch"><span class="body-text-content"><span><span style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;" data-mce-style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;"><meta charset="utf-8"><span style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;" data-mce-style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;">f(a:Int) -> Int { return { b:Int in return (a/b, a%b != 0)} } has type (Int) -> (Int -> (Int, Bool))</span></span></span></span></div><div class="_stretch"><span class="body-text-content"><span><span style="orphans: auto; text-align: start; text-indent: 0px; widows: 1; float: none; display: inline !important; background-color: rgb(255, 255, 255);" data-mce-style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;"><span style="orphans: auto; text-align: start; text-indent: 0px; widows: 1; float: none; display: inline !important; background-color: rgb(255, 255, 255);" data-mce-style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;">Of course this need to be refined and formalized.</span></span></span></span></div><div class="_stretch"><span class="body-text-content"><span><span style="orphans: auto; text-align: start; text-indent: 0px; widows: 1; float: none; display: inline !important; background-color: rgb(255, 255, 255);" data-mce-style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;"><span style="orphans: auto; text-align: start; text-indent: 0px; widows: 1; float: none; display: inline !important; background-color: rgb(255, 255, 255);" data-mce-style="color: #000000; font-family: SFNSText, 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 22.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;"><br data-mce-bogus="1"></span></span></span></span></div><div class="_stretch"><span class="body-text-content"><blockquote type="cite" class="quoted-plain-text">which makes more sense but is less clear to most programmers than the current syntax. </blockquote></span></div><div class="_stretch"><br data-mce-bogus="1"></div><div class="_stretch"><span class="body-text-content"><span>In my opinion, what are clear for programmers are what they understand, a reference section explaining these concepts could do the work of clarifying things.</span></span></div><div class="_stretch"><span class="body-text-content"><br><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text"><br></blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text">When curried function will come back (if it come back, which is a personal hope) that will avoid many refactoring.</blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text"><br></blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text">I think that, write this : let f:(Int, Int) throws -> Int = (+) seem a bit ugly for this purpose</blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text">let f:(Int -> Int) -> Int = (+) seem more suitable.</blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text"><br></blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text">We could imagine that in the future the compile could automatically create a closure if the programmer define something like</blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text"><br></blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text">let lmul: (Int) -> (Int) -> (Int) = (*)</blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text"><br></blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text">and then, doing the habitual stuffs : let mulOfTwo = lmul(2)</blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text"><br></blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text"><br></blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text">Kind regards,</blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text">--</blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text">jcnm</blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text"><br></blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text">_______________________________________________</blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text">swift-evolution mailing list</blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text"><a href="mailto:swift-evolution@swift.org" onclick="return false;" data-mce-href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><blockquote type="cite" class="quoted-plain-text"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" data-mce-href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></blockquote></blockquote><blockquote type="cite" class="quoted-plain-text"><br></blockquote></span></div></body></html>