[swift-evolution] [Pitch] [Phase 2] New `permuting` keyword for protocols

Adrian Zubarev adrian.zubarev at devandartist.com
Mon Dec 26 05:30:00 CST 2016

I think I revise what I said about value semantics in my last post.

let chain: T = foo.a()

let new = chain
new. // should not see `a` here
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. =)

Adrian Zubarev
Sent with Airmail

Am 26. Dezember 2016 um 12:11:23, Adrian Zubarev (adrian.zubarev at devandartist.com) schrieb:

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.

permuting protocol T {
    func a()
    func b()
    func c()
    func d()

var foo: T = …

func boo(_ val: T) -> 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
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.

Did I understood your point correctly here?

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. :)

Adrian Zubarev
Sent with Airmail

Am 26. Dezember 2016 um 11:50:50, Xiaodi Wu (xiaodi.wu at gmail.com) schrieb:

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?

That is, if `foo.a()` can be passed as an argument to an arbitrary function of type `(T) -> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161226/e983c3c9/attachment.html>

More information about the swift-evolution mailing list