<div dir="ltr">Hello.<div><br></div><div>The proposal can be also read at <a href="https://gist.github.com/vmartinelli/67d6ad234c7a4e14f8d5">https://gist.github.com/vmartinelli/67d6ad234c7a4e14f8d5</a></div><div><br></div><div>Original thread: <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160125/008508.html">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160125/008508.html</a></div><div><br></div><div>Opinions, comments and corrections (including on English grammar) are all welcome. :-)<br><div><br></div><div>-Van</div><div><br></div><div>---------</div><div><br></div><div><h1 style="font-size:2.25em;margin-right:0px;margin-bottom:16px;margin-left:0px;line-height:1.2;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;margin-top:0px!important">Instance Operators</h1><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px"><li style="">Proposal: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/NNNN-instance-operators.md" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none">SE-NNNN</a></li><li style="">Author: <a href="https://github.com/vmartinelli" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none">Vanderlei Martinelli</a></li><li style="">Status: <strong style="">Awaiting review</strong></li><li style="">Review manager: TBD</li></ul><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;">Introduction</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px">The proposal aims to move operator implementation from the global and static scope into extension/struct/class instance scope.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px">Swift-evolution thread: <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160125/008508.html" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none">link to the discussion thread for that proposal</a></p><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;">Motivation</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px">When writing the protocol interface the operator is declarated inside the scope of that protocol, but its implementation has to be static and global. This, besides being inconsistent, might not the behaviour expected by programmers coming from other languages that have some kind of support for interface/protocol and operator implementation.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px">Example:</p><div class="" style="margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px"><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal"><span class="" style="color:rgb(150,152,150)">// MARK: - protocol</span>

<span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">protocol</span> MyDoubleType {
    <span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">func</span> <span class="" style="color:rgb(121,93,163)">someUsefulFunction</span>()

    <span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">func</span> <span class="" style="color:rgb(121,93,163)">*</span>(lhs: <span class="" style="color:rgb(167,29,93)">Self</span>, rhs: <span class="" style="color:rgb(167,29,93)">Self</span>) <span class="" style="color:rgb(167,29,93)">-&gt;</span> Self
    <span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">postfix</span> <span class="" style="color:rgb(167,29,93)">func</span> <span class="" style="color:rgb(121,93,163)">++</span>(<span class="" style="color:rgb(121,93,163)">inout</span> <span class="" style="">x</span>: <span class="" style="color:rgb(167,29,93)">Self</span>) <span class="" style="color:rgb(167,29,93)">-&gt;</span> Self
}

<span class="" style="color:rgb(150,152,150)">// MARK: - implementation</span>

<span class="" style="color:rgb(167,29,93)">extension</span> <span class="" style="color:rgb(0,134,179)">Double</span>: MyDoubleType {

    <span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">func</span> <span class="" style="color:rgb(121,93,163)">someUsefulFunction</span>() {
        <span class="" style="color:rgb(150,152,150)">// ...</span>
    }

    <span class="" style="color:rgb(150,152,150)">// we cannot implement the operators here...</span>

}

<span class="" style="color:rgb(150,152,150)">// ... but have to implement them here</span>

<span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">func</span> <span class="" style="color:rgb(121,93,163)">*</span>(lhs: <span class="" style="color:rgb(0,134,179)">Double</span>, rhs: <span class="" style="color:rgb(0,134,179)">Double</span>) <span class="" style="color:rgb(167,29,93)">-&gt;</span> <span class="" style="color:rgb(0,134,179)">Double</span> {
    <span class="" style="color:rgb(167,29,93)">return</span> lhs<span class="" style="color:rgb(167,29,93)">.</span>multipliedBy(rhs)
}

<span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">postfix</span> <span class="" style="color:rgb(167,29,93)">func</span> <span class="" style="color:rgb(121,93,163)">++</span>(<span class="" style="color:rgb(121,93,163)">inout</span> <span class="" style="">x</span>: <span class="" style="color:rgb(0,134,179)">Double</span>) <span class="" style="color:rgb(167,29,93)">-&gt;</span> <span class="" style="color:rgb(0,134,179)">Double</span> {
    x <span class="" style="color:rgb(167,29,93)">+=</span> <span class="" style="color:rgb(0,134,179)">1</span><span class="" style="color:rgb(167,29,93)">.</span><span class="" style="color:rgb(0,134,179)">0</span>
    <span class="" style="color:rgb(167,29,93)">return</span> x
}</pre></div><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px">Also the current implementation does not leave much room for future expansion in the use of operators (such as conversion between values, for example).</p><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;">Proposed solution</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px">Move the operator implementation into the extension/struct/class scope and turn operator funcs into instance funcs, using the <code style="font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">operator</code> keyword.</p><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;">Detailed design</h2><h3 style="margin-top:1em;margin-bottom:16px;line-height:1.43;font-size:1.5em;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;">Protocol conformance</h3><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px">After the change the above code can be written like the example bellow.</p><div class="" style="margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px"><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal"><span class="" style="color:rgb(150,152,150)">// MARK: - protocol</span>

<span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">protocol</span> MyDoubleType {
    <span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">func</span> <span class="" style="color:rgb(121,93,163)">someUsefulFunction</span>()

    <span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">operator</span> <span class="" style="color:rgb(167,29,93)">*</span>(rhs: <span class="" style="color:rgb(167,29,93)">Self</span>) <span class="" style="color:rgb(167,29,93)">-&gt;</span> <span class="" style="color:rgb(167,29,93)">Self</span>
    <span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">mutating</span> <span class="" style="color:rgb(167,29,93)">postfix</span> <span class="" style="color:rgb(167,29,93)">operator</span> <span class="" style="color:rgb(167,29,93)">++</span>() <span class="" style="color:rgb(167,29,93)">-&gt;</span> <span class="" style="color:rgb(167,29,93)">Self</span>
}

<span class="" style="color:rgb(150,152,150)">// MARK: - implementation</span>

<span class="" style="color:rgb(167,29,93)">extension</span> <span class="" style="color:rgb(0,134,179)">Double</span>: MyDoubleType {

    <span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">func</span> <span class="" style="color:rgb(121,93,163)">someUsefulFunction</span>() {
        <span class="" style="color:rgb(150,152,150)">// ...</span>
    }

    <span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">operator</span> <span class="" style="color:rgb(167,29,93)">*</span>(rhs: <span class="" style="color:rgb(0,134,179)">Double</span>) <span class="" style="color:rgb(167,29,93)">-&gt;</span> <span class="" style="color:rgb(0,134,179)">Double</span> {
        <span class="" style="color:rgb(167,29,93)">return</span> <span class="" style="color:rgb(167,29,93)">self</span><span class="" style="color:rgb(167,29,93)">.</span>multipliedBy(rhs)
    }

    <span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">mutating</span> <span class="" style="color:rgb(167,29,93)">postfix</span> <span class="" style="color:rgb(167,29,93)">operator</span> <span class="" style="color:rgb(167,29,93)">++</span>() <span class="" style="color:rgb(167,29,93)">-&gt;</span> <span class="" style="color:rgb(0,134,179)">Double</span> {
       <span class="" style="color:rgb(167,29,93)">self</span> <span class="" style="color:rgb(167,29,93)">+=</span> <span class="" style="color:rgb(0,134,179)">1</span><span class="" style="color:rgb(167,29,93)">.</span><span class="" style="color:rgb(0,134,179)">0</span>
       <span class="" style="color:rgb(167,29,93)">return</span> <span class="" style="color:rgb(167,29,93)">self</span>
    }

}</pre></div><h3 style="margin-top:1em;margin-bottom:16px;line-height:1.43;font-size:1.5em;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;">Operator funcs everywhere</h3><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px">An operator does not have to be implemented only to conform to a protocol, however. It can be also be implemented in any other place where a common func is. This means that even the current form can be supported.</p><h3 style="margin-top:1em;margin-bottom:16px;line-height:1.43;font-size:1.5em;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;">Operator internal names</h3><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px">Perhaps because of the internal implementation of Swift, operators have to have names to be handled. The suggestion is to adopt <code style="font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">__operator__GreaterThanOrEqual</code> for a <code style="font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">&gt;=</code> operator, as example. The operator introduction would be:</p><div class="" style="margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px"><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal"><span class="" style="color:rgb(167,29,93)">infix</span> <span class="" style="color:rgb(167,29,93)">operator</span> <span class="" style="color:rgb(167,29,93)">&gt;=</span> {
    <span class="" style="color:rgb(167,29,93)">associativity</span> <span class="" style="color:rgb(167,29,93)">none</span>
    <span class="" style="color:rgb(167,29,93)">precedence</span> <span class="" style="color:rgb(0,134,179)">130</span>
    name <span class="" style="color:rgb(24,54,145)"><span class="" style="">&quot;</span>GreaterThanOrEqual<span class="" style="">&quot;</span></span>
}</pre></div><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px">So the code will be written like this...</p><div class="" style="margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px"><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal"><span class="" style="color:rgb(167,29,93)">struct</span> MyStruct {
    <span class="" style="color:rgb(167,29,93)">operator</span> <span class="" style="color:rgb(167,29,93)">&gt;=</span>(other: MyStruct) <span class="" style="color:rgb(167,29,93)">-&gt;</span> <span class="" style="color:rgb(0,134,179)">Bool</span> {
        <span class="" style="color:rgb(167,29,93)">return</span> <span class="" style="color:rgb(167,29,93)">...</span>
    }
}</pre></div><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px">... but translated internally to this:</p><div class="" style="margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px"><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal"><span class="" style="color:rgb(167,29,93)">struct</span> MyStruct {
    <span class="" style="color:rgb(167,29,93)">func</span> <span class="" style="color:rgb(121,93,163)">__operator__GreaterThanOrEqual</span>(other: MyStruct) <span class="" style="color:rgb(167,29,93)">-&gt;</span> <span class="" style="color:rgb(0,134,179)">Bool</span> {
        <span class="" style="color:rgb(167,29,93)">return</span> <span class="" style="color:rgb(167,29,93)">...</span>
    }
}</pre></div><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;">Impact on existing code</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px">Since after this change an operator can be implemented in any other place where a common func can be, the current implementation may continue to exist, but marked as deprecated with a compiler/analyser warning.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px">Also the <code style="font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">func</code> keyword would be deprecated for operators as well, using the <code style="font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">operator</code> to declare/implement an operator func.</p><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;">Alternatives considered</h2><h3 style="margin-top:1em;margin-bottom:16px;line-height:1.43;font-size:1.5em;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;">Status quo</h3><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px">Leave things as they are. Even being inconsistent or not allowing new possibilities that instance operators will bring.</p><h3 style="margin-top:1em;margin-bottom:16px;line-height:1.43;font-size:1.5em;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;">Static implementation inside extension/struct/class scope</h3><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px">This is the way operators are implemented in C#, for example. The change would be only aesthetic. The functionality would remain the same as today.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px">As the types may differ from protocol/structure/class, this would allow state within the scope of operators that have nothing to do with that type. Not a good thing. In this case it might be better to keep things as they are.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px">Example:</p><div class="" style="color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;margin-bottom:0px!important"><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal"><span class="" style="color:rgb(150,152,150)">// MARK: - protocol</span>

<span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">protocol</span> MyDoubleType {
    <span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">func</span> <span class="" style="color:rgb(121,93,163)">someUsefulFunction</span>()

    <span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">static</span> <span class="" style="color:rgb(167,29,93)">operator</span> <span class="" style="color:rgb(167,29,93)">*</span>(lhs: <span class="" style="color:rgb(167,29,93)">Self</span>, rhs: <span class="" style="color:rgb(167,29,93)">Self</span>) <span class="" style="color:rgb(167,29,93)">-&gt;</span> <span class="" style="color:rgb(167,29,93)">Self</span>
    <span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">static</span> <span class="" style="color:rgb(167,29,93)">operator</span> <span class="" style="color:rgb(167,29,93)">/</span>(lhs: <span class="" style="color:rgb(0,134,179)">Int64</span>, rhs: <span class="" style="color:rgb(0,134,179)">Int64</span>) <span class="" style="color:rgb(167,29,93)">-&gt;</span> <span class="" style="color:rgb(0,134,179)">Int64</span> <span class="" style="color:rgb(150,152,150)">// what?</span>
    <span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">static</span> <span class="" style="color:rgb(167,29,93)">postfix</span> <span class="" style="color:rgb(167,29,93)">operator</span> <span class="" style="color:rgb(167,29,93)">++</span>(<span class="" style="color:rgb(167,29,93)">inout</span> x: <span class="" style="color:rgb(167,29,93)">Self</span>) <span class="" style="color:rgb(167,29,93)">-&gt;</span> <span class="" style="color:rgb(167,29,93)">Self</span>
}

<span class="" style="color:rgb(150,152,150)">// MARK: - implementation</span>

<span class="" style="color:rgb(167,29,93)">extension</span> <span class="" style="color:rgb(0,134,179)">Double</span>: MyDoubleType {

    <span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">func</span> <span class="" style="color:rgb(121,93,163)">someUsefulFunction</span>() {
        <span class="" style="color:rgb(150,152,150)">// ...</span>
    }

    <span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">static</span> <span class="" style="color:rgb(167,29,93)">operator</span> <span class="" style="color:rgb(167,29,93)">*</span>(lhs: <span class="" style="color:rgb(0,134,179)">Double</span>, rhs: <span class="" style="color:rgb(0,134,179)">Double</span>) <span class="" style="color:rgb(167,29,93)">-&gt;</span> <span class="" style="color:rgb(0,134,179)">Double</span> {
        <span class="" style="color:rgb(167,29,93)">return</span> lhs<span class="" style="color:rgb(167,29,93)">.</span>multipliedBy(rhs)
    }

    <span class="" style="color:rgb(150,152,150)">// this should be implemented inside a Int64 type, not here...</span>
    <span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">static</span> <span class="" style="color:rgb(167,29,93)">operator</span> <span class="" style="color:rgb(167,29,93)">/</span>(lhs: <span class="" style="color:rgb(0,134,179)">Int64</span>, rhs: <span class="" style="color:rgb(0,134,179)">Int64</span>) <span class="" style="color:rgb(167,29,93)">-&gt;</span> <span class="" style="color:rgb(0,134,179)">Int64</span> {
        <span class="" style="color:rgb(150,152,150)">// ...</span>
    }

    <span class="" style="color:rgb(167,29,93)">public</span> <span class="" style="color:rgb(167,29,93)">static</span> <span class="" style="color:rgb(167,29,93)">postfix</span> <span class="" style="color:rgb(167,29,93)">operator</span> <span class="" style="color:rgb(167,29,93)">++</span>(<span class="" style="color:rgb(167,29,93)">inout</span> x: <span class="" style="color:rgb(0,134,179)">Double</span>) <span class="" style="color:rgb(167,29,93)">-&gt;</span> <span class="" style="color:rgb(0,134,179)">Double</span> {
        x <span class="" style="color:rgb(167,29,93)">+=</span> <span class="" style="color:rgb(0,134,179)">1</span><span class="" style="color:rgb(167,29,93)">.</span><span class="" style="color:rgb(0,134,179)">0</span>
        <span class="" style="color:rgb(167,29,93)">return</span> x
    }

}</pre><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal"><br></pre></div></div></div></div>