<html><head></head><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yui_3_16_0_ym19_1_1481458213339_3134"><span>Thanks for the suggestion,</span></div><div id="yui_3_16_0_ym19_1_1481458213339_3134"><span><br></span></div><div id="yui_3_16_0_ym19_1_1481458213339_3134"><span id="yui_3_16_0_ym19_1_1481458213339_3133">I have updated the proposal with the error and with the notes on `fileprivate` -> `private`</span></div><div id="yui_3_16_0_ym19_1_1481458213339_3134"><span><br></span></div><div id="yui_3_16_0_ym19_1_1481458213339_3134"><span id="yui_3_16_0_ym19_1_1481458213339_3162">/Tommaso</span></div> <div class="qtdSeparateBR"><br><br></div><div class="yahoo_quoted" style="display: block;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div dir="ltr"><font size="2" face="Arial"> On Sunday, December 11, 2016 5:55 AM, Derrick Ho <wh1pch81n@gmail.com> wrote:<br></font></div> <br><br> <div class="y_msg_container"><div id="yiv1303795262"><div><div dir="ltr">You may want to add the specific error to your proposal. <div><br clear="none"></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style=""><b>error: member operator '•|' must have at least one argument of type 'NonEmptyArray<Element>'</b></span></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;"><span style=""><b> public static func •|<Element>(lhs: Element, rhs: [Element]) -> NonEmptyArray<Element></b></span></div></div></div><br clear="none"><div class="yiv1303795262yqt7024955512" id="yiv1303795262yqt63283"><div class="yiv1303795262gmail_quote"><div dir="ltr">On Sat, Dec 10, 2016 at 11:49 PM Derrick Ho <<a rel="nofollow" shape="rect" ymailto="mailto:wh1pch81n@gmail.com" target="_blank" href="mailto:wh1pch81n@gmail.com">wh1pch81n@gmail.com</a>> wrote:<br clear="none"></div><blockquote class="yiv1303795262gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="yiv1303795262gmail_msg" dir="ltr">I placed he code you wrote in the proposal in playgrounds and it works perfectly. (reproduced below). Overloading operators used to only happen globally and since swift 3 they allowed you to put then inside the class/struct<div class="yiv1303795262gmail_msg"><br clear="none" class="yiv1303795262gmail_msg"></div><div class="yiv1303795262gmail_msg"><pre class="yiv1303795262gmail_msg" style="font-family:consolas, 'liberation mono', menlo, courier, monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:16px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);color:rgb(51,51,51);"><code class="yiv1303795262gmail_msg" style="font-family:consolas, 'liberation mono', menlo, courier, monospace;padding:0px;margin:0px;background-color:transparent;border:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal;">public struct NonEmptyArray<Element> {
fileprivate var elements: Array<Element>
fileprivate init(array: [Element]) {
self.elements = array
}
}
//Overload 1
public func •|<Element>(lhs: Element, rhs: [Element]) -> NonEmptyArray<Element> {
return NonEmptyArray(array: rhs + [lhs])
}
//Overload 2
public func •|<Element>(lhs: Element, rhs: NonEmptyArray<Element>) -> NonEmptyArray<Element> {
return NonEmptyArray(array: [lhs] + rhs.elements)
}
//Overload 3
public func •|<Element>(lhs: NonEmptyArray<Element>, rhs: NonEmptyArray<Element>) -> NonEmptyArray<Element> {
return NonEmptyArray(array: lhs.elements + rhs.elements)
}</code></pre></div><div class="yiv1303795262gmail_msg"><br clear="none" class="yiv1303795262gmail_msg"></div><div class="yiv1303795262gmail_msg">However, as you have detailed when you place those overloads inside the struct/class, it does not work. Actually I get an error that says that at least ONE of the arguments needs to be the same type. In this case one of them needs to be NonEmptyArray<Element>. It is clearly not a bug, but rather a swift rule.</div><div class="yiv1303795262gmail_msg"><br clear="none" class="yiv1303795262gmail_msg"></div><div class="yiv1303795262gmail_msg">My recommendation is to just keep those overloads as global. Is there a particular advantage to putting them inside the struct/class?<br clear="none" class="yiv1303795262gmail_msg"><div class="yiv1303795262gmail_msg"><br clear="none" class="yiv1303795262gmail_msg"></div><div class="yiv1303795262gmail_msg"><br clear="none" class="yiv1303795262gmail_msg"></div></div></div><br clear="none" class="yiv1303795262gmail_msg"><div class="yiv1303795262gmail_quote yiv1303795262gmail_msg"><div class="yiv1303795262gmail_msg" dir="ltr">On Sat, Dec 10, 2016 at 8:36 PM David Sweeris via swift-evolution <<a rel="nofollow" shape="rect" class="yiv1303795262gmail_msg" ymailto="mailto:swift-evolution@swift.org" target="_blank" href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br clear="none" class="yiv1303795262gmail_msg"></div><blockquote class="yiv1303795262gmail_quote yiv1303795262gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="yiv1303795262gmail_msg" style="word-wrap:break-word;"><div class="yiv1303795262gmail_msg"><blockquote class="yiv1303795262gmail_msg" type="cite"><div class="yiv1303795262gmail_msg">On Dec 10, 2016, at 5:29 PM, David Sweeris via swift-evolution <<a rel="nofollow" shape="rect" class="yiv1303795262gmail_msg" ymailto="mailto:swift-evolution@swift.org" target="_blank" href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:</div><br clear="none" class="yiv1303795262m_8139447927534648323m_-1969521834013891672Apple-interchange-newline yiv1303795262gmail_msg"><div class="yiv1303795262gmail_msg"><div class="yiv1303795262gmail_msg" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;"><blockquote class="yiv1303795262gmail_msg" type="cite"><div class="yiv1303795262gmail_msg"><br clear="none" class="yiv1303795262m_8139447927534648323m_-1969521834013891672Apple-interchange-newline yiv1303795262gmail_msg">On Dec 10, 2016, at 4:54 PM, Tommaso Piazza via swift-evolution <<a rel="nofollow" shape="rect" class="yiv1303795262gmail_msg" ymailto="mailto:swift-evolution@swift.org" target="_blank" href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:</div><br clear="none" class="yiv1303795262m_8139447927534648323m_-1969521834013891672Apple-interchange-newline yiv1303795262gmail_msg"><div class="yiv1303795262gmail_msg"><div class="yiv1303795262gmail_msg"><div class="yiv1303795262gmail_msg" style="background-color:rgb(255,255,255);font-family:HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:16px;"><div class="yiv1303795262gmail_msg" dir="ltr" id="yiv1303795262m_8139447927534648323m_-1969521834013891672yui_3_16_0_ym19_1_1481417388759_3640">Hello,</div><div class="yiv1303795262gmail_msg" dir="ltr" id="yiv1303795262m_8139447927534648323m_-1969521834013891672yui_3_16_0_ym19_1_1481417388759_3640"><br clear="none" class="yiv1303795262gmail_msg"></div><div class="yiv1303795262gmail_msg" dir="ltr" id="yiv1303795262m_8139447927534648323m_-1969521834013891672yui_3_16_0_ym19_1_1481417388759_3640">I have written a small proposal that would allow overloads of operators in structs/classes non only based on the types of the operands but on the return type as well.</div><div class="yiv1303795262gmail_msg" dir="ltr" id="yiv1303795262m_8139447927534648323m_-1969521834013891672yui_3_16_0_ym19_1_1481417388759_3640"><br clear="none" class="yiv1303795262gmail_msg"></div><div class="yiv1303795262gmail_msg" dir="ltr" id="yiv1303795262m_8139447927534648323m_-1969521834013891672yui_3_16_0_ym19_1_1481417388759_3640">Please let me know you thoughts,</div><div class="yiv1303795262gmail_msg" dir="ltr" id="yiv1303795262m_8139447927534648323m_-1969521834013891672yui_3_16_0_ym19_1_1481417388759_3640">/Tommaso</div><div class="yiv1303795262gmail_msg" dir="ltr" id="yiv1303795262m_8139447927534648323m_-1969521834013891672yui_3_16_0_ym19_1_1481417388759_3640"><br clear="none" class="yiv1303795262gmail_msg"></div><div class="yiv1303795262gmail_msg" dir="ltr" id="yiv1303795262m_8139447927534648323m_-1969521834013891672yui_3_16_0_ym19_1_1481417388759_3640"><a rel="nofollow" shape="rect" class="yiv1303795262gmail_msg" id="yiv1303795262m_8139447927534648323m_-1969521834013891672yui_3_16_0_ym19_1_1481417388759_3639" target="_blank" href="https://github.com/blender/swift-evolution/blob/proposal/overloads-return-type/NNNN-allow-operator-overloads-in-structs-or-classes-based-on-return-type.md">https://github.com/blender/swift-evolution/blob/proposal/overloads-return-type/NNNN-allow-operator-overloads-in-structs-or-classes-based-on-return-type.md</a><br clear="none" class="yiv1303795262gmail_msg"></div></div></div></div></blockquote><br clear="none" class="yiv1303795262gmail_msg"></div><div class="yiv1303795262gmail_msg" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">That seems like a bug to me… Dunno, maybe it’s intentional and I’m just not aware of the reasoning.</div></div></blockquote><div class="yiv1303795262gmail_msg"><br clear="none" class="yiv1303795262gmail_msg"></div></div></div><div class="yiv1303795262gmail_msg" style="word-wrap:break-word;"><div class="yiv1303795262gmail_msg">Actually, since the error message correctly parses the code, it probably <i class="yiv1303795262gmail_msg">is</i> intentional… I don’t see the problem, myself, but I guess I’d have to know why it’s considered an error before judging whether I think we should remove the restriction.</div><div class="yiv1303795262gmail_msg"><br clear="none" class="yiv1303795262gmail_msg"></div>- Dave Sweeris</div>_______________________________________________<br clear="none" class="yiv1303795262gmail_msg">
swift-evolution mailing list<br clear="none" class="yiv1303795262gmail_msg">
<a rel="nofollow" shape="rect" class="yiv1303795262gmail_msg" ymailto="mailto:swift-evolution@swift.org" target="_blank" href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br clear="none" class="yiv1303795262gmail_msg">
<a rel="nofollow" shape="rect" class="yiv1303795262gmail_msg" target="_blank" href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br clear="none" class="yiv1303795262gmail_msg">
</blockquote></div></blockquote></div></div></div></div><br><br></div> </div> </div> </div></div></body></html>