Should the following compile?<br><br>let bar = foo.a()<br>func f(_ g: T) {<br>  _ = g.a()<br>}<br>f(bar)<br><br>If so, your proposal cannot guarantee each method is called only once. If not, how can bar be of type T?<br><br><div class="gmail_quote"><div dir="ltr">On Mon, Dec 26, 2016 at 06:30 Adrian Zubarev &lt;<a href="mailto:adrian.zubarev@devandartist.com">adrian.zubarev@devandartist.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg"><div class="m_2486499801731300355bloop_markdown gmail_msg"><p class="gmail_msg">I think I revise what I said about value semantics in my last post.</p>

<pre class="gmail_msg"><code class="m_2486499801731300355swift gmail_msg">let chain: T = foo.a()

let new = chain
new. // should not see `a` here
</code></pre>

<p class="gmail_msg">It’s more something like a local scoped chain. I’m not sure how to call it correctly here. I’m not a native English speaker. =)</p>

<p class="gmail_msg"></p></div><div class="m_2486499801731300355bloop_original_html gmail_msg"></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="m_2486499801731300355bloop_original_html gmail_msg"><div id="m_2486499801731300355bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto" class="gmail_msg"><br class="gmail_msg"></div> <br class="gmail_msg"> <div id="m_2486499801731300355bloop_sign_1482751593527631872" class="m_2486499801731300355bloop_sign gmail_msg"><div style="font-family:helvetica,arial;font-size:13px" class="gmail_msg">-- <br class="gmail_msg">Adrian Zubarev<br class="gmail_msg">Sent with Airmail</div></div> <br class="gmail_msg"></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="m_2486499801731300355bloop_original_html gmail_msg"><p class="m_2486499801731300355airmail_on gmail_msg">Am 26. Dezember 2016 um 12:11:23, Adrian Zubarev (<a href="mailto:adrian.zubarev@devandartist.com" class="gmail_msg" target="_blank">adrian.zubarev@devandartist.com</a>) schrieb:</p> <blockquote type="cite" class="m_2486499801731300355clean_bq gmail_msg"><span class="gmail_msg"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"></div><div class="gmail_msg">








<div class="m_2486499801731300355bloop_markdown gmail_msg">
<p class="gmail_msg">By ‘calling once’ I meant, calling once at a single permutation
chain. If the chain is escaped or followed by a non-permuting
member that returns the same protocol, you’d have the ability to
use all members at the starting point of the new chain.</p>
<pre class="gmail_msg"><code class="m_2486499801731300355swift gmail_msg">permuting protocol T {
    func a()
    func b()
    func c()
    func d()
}

var foo: T = …

func boo(_ val: T) -&gt; U {
    // Here val escapes the chain and creates a new one
    // That means that you can create a local permutation chain here again
      
    val.a() // we can use `a` here
    return …
}

boo(foo.a()) // a is immediately invoked here
</code></pre>
<p class="gmail_msg">I imagine this keyword to follow value semantics, so that any
possible mutation is handled locally with a nice extra ability of
permutation member chaining.</p>
<p class="gmail_msg">Did I understood your point correctly here?</p>
<hr class="gmail_msg">
<p class="gmail_msg">Sure the idea needs to be more fleshed out, but I’m curious if
that’s something that we might see in Swift one day. :)</p>
</div>
<div class="m_2486499801731300355bloop_original_html gmail_msg">

<div id="m_2486499801731300355bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto" class="gmail_msg">
<br class="gmail_msg"></div>
<br class="gmail_msg">
<div id="m_2486499801731300355bloop_sign_1482749838336907008" class="m_2486499801731300355bloop_sign gmail_msg">
<div style="font-family:helvetica,arial;font-size:13px" class="gmail_msg">
-- <br class="gmail_msg">
Adrian Zubarev<br class="gmail_msg">
Sent with Airmail</div>
</div>
<br class="gmail_msg">
<p class="m_2486499801731300355airmail_on gmail_msg">Am 26. Dezember 2016 um 11:50:50, Xiaodi Wu
(<a href="mailto:xiaodi.wu@gmail.com" class="gmail_msg" target="_blank">xiaodi.wu@gmail.com</a>)
schrieb:</p>
<blockquote type="cite" class="m_2486499801731300355clean_bq gmail_msg">
<div class="gmail_msg"><span class="gmail_msg"><span style="color:rgb(0,0,0);font-family:&#39;helvetica Neue&#39;,helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);display:inline!important;float:none" class="gmail_msg">
Given `foo: T` and methods a(), b(), c(), d(), each of which can
only be called once, how can the return value of these methods be
represented in the type system?</span><br style="color:rgb(0,0,0);font-family:&#39;helvetica Neue&#39;,helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg">

<br style="color:rgb(0,0,0);font-family:&#39;helvetica Neue&#39;,helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg">

<span style="color:rgb(0,0,0);font-family:&#39;helvetica Neue&#39;,helvetica;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);display:inline!important;float:none" class="gmail_msg">
That is, if `foo.a()` can be passed as an argument to an arbitrary
function of type `(T) -&gt; U`, either the function cannot
immediately invoke a(), in which case foo is not of type T, or it
can immediately invoke a(), in which case your keyword does not
work.</span></span></div>
</blockquote>
</div>
<div class="m_2486499801731300355bloop_markdown gmail_msg"></div>


</div></div></span></blockquote></div></div></blockquote></div>